SharpVectors.Dom.Css.CssStyleDeclaration.RemoveProperty C# (CSharp) Method

RemoveProperty() public method

Used to remove a CSS property if it has been explicitly set within this declaration block.
NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly.
public RemoveProperty ( string propertyName ) : string
propertyName string The name of the CSS property. See the CSS property index.
return string
        public string RemoveProperty(string propertyName)
        {
            if(ReadOnly) throw new DomException(DomExceptionType.NoModificationAllowedErr);

            if(styles.ContainsKey(propertyName))
            {
                SharpCssStyle s = (SharpCssStyle)styles[propertyName];
                styles.Remove(propertyName);
                return s.Value;
            }
            else return String.Empty;
        }

Usage Example

示例#1
0
        public void TestCssStyleDeclaration()
        {
            rule = (CssStyleRule)cssStyleSheet.CssRules[0];
            CssStyleDeclaration csd = (CssStyleDeclaration)rule.Style;

            Assert.AreEqual("fill:#123456 !important;opacity:0.5;", csd.CssText);
            Assert.AreEqual(2, csd.Length);
            Assert.AreSame(rule, csd.ParentRule);
            Assert.AreEqual("important", csd.GetPropertyPriority("fill"));
            Assert.AreEqual("0.5", csd.GetPropertyValue("opacity"));
            Assert.AreEqual("", csd.GetPropertyPriority("opacity"));
            Assert.AreEqual("#123456", csd.GetPropertyValue("fill"));

            csd.SetProperty("opacity", "0.8", "");
            Assert.AreEqual("0.8", csd.GetPropertyValue("opacity"));
            Assert.AreEqual("", csd.GetPropertyPriority("opacity"));

            csd.SetProperty("opacity", "0.2", "important");
            Assert.AreEqual("0.2", csd.GetPropertyValue("opacity"));
            Assert.AreEqual("important", csd.GetPropertyPriority("opacity"));

            Assert.AreEqual("0.2", csd.RemoveProperty("opacity"));
            Assert.AreEqual(1, csd.Length);

            csd.SetProperty("foo", "bar", "");
            Assert.AreEqual("bar", csd.GetPropertyValue("foo"));
            Assert.AreEqual(2, csd.Length);

            // reset values
            csd.RemoveProperty("foo");
            csd.SetProperty("opacity", "0.5", "");
        }