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

GetPropertyCssValue() public method

Used to retrieve the object representation of the value of a CSS property if it has been explicitly set within this declaration block. This method returns null if the property is a shorthand property. Shorthand property values can only be accessed and modified as strings, using the getPropertyValue and setProperty methods.
public GetPropertyCssValue ( string propertyName ) : ICssValue
propertyName string The name of the CSS property. See the CSS property index.
return ICssValue
        public virtual ICssValue GetPropertyCssValue(string propertyName)
        {
            if(styles.ContainsKey(propertyName))
            {
                SharpCssStyle scs = (SharpCssStyle)styles[propertyName];
                if(scs.CssValue == null)
                {
                    scs.CssValue = CssValue.GetCssValue(scs.Value, ReadOnly);
                }
                return scs.CssValue;
            }
            else
            {
                return null;
            }
        }

Usage Example

示例#1
0
        public void TestRectValue()
        {
            CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[1]).Style;
            CssValue            val = (CssValue)csd.GetPropertyCssValue("rect");

            Assert.IsTrue(val is CssPrimitiveValue);
            CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("rect");

            Assert.AreEqual("rect(10cm 23px 45px 89px)", primValue.CssText);
            Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType);
            Assert.AreEqual(CssPrimitiveType.Rect, primValue.PrimitiveType);
            IRect rect = primValue.GetRectValue();

            ICssPrimitiveValue rectValue = rect.Top;

            Assert.AreEqual(100, rectValue.GetFloatValue(CssPrimitiveType.Mm));
            Assert.AreEqual(CssPrimitiveType.Cm, rectValue.PrimitiveType);

            rectValue = rect.Right;
            Assert.AreEqual(23, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);

            rectValue = rect.Bottom;
            Assert.AreEqual(45, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);

            rectValue = rect.Left;
            Assert.AreEqual(89, rectValue.GetFloatValue(CssPrimitiveType.Px));
            Assert.AreEqual(CssPrimitiveType.Px, rectValue.PrimitiveType);
        }
All Usage Examples Of SharpVectors.Dom.Css.CssStyleDeclaration::GetPropertyCssValue