示例#1
0
        private bool HasStylesheetValue(Widget w, PropertyInfo property)
        {
            if (Stylesheet == null)
            {
                return(false);
            }

            var styleName = w.StyleName;

            if (string.IsNullOrEmpty(styleName))
            {
                styleName = Stylesheet.DefaultStyleName;
            }

            var stylesheet = Stylesheet;

            // Find styles dict of that widget
            var stylesDictPropertyName = w.GetType().Name + "Styles";
            var stylesDictProperty     = stylesheet.GetType().GetRuntimeProperty(stylesDictPropertyName);

            if (stylesDictProperty == null)
            {
                return(false);
            }

            var stylesDict = (IDictionary)stylesDictProperty.GetValue(stylesheet);

            if (stylesDict == null)
            {
                return(false);
            }

            // Fetch style from the dict
            var style = stylesDict[styleName];

            // Now find corresponding property
            PropertyInfo styleProperty = null;

            var stylePropertyPathAttribute = property.FindAttribute <StylePropertyPathAttribute>();

            if (stylePropertyPathAttribute != null)
            {
                var parts = stylePropertyPathAttribute.Name.Split('.');

                for (var i = 0; i < parts.Length; ++i)
                {
                    styleProperty = style.GetType().GetRuntimeProperty(parts[i]);

                    if (i < parts.Length - 1)
                    {
                        style = styleProperty.GetValue(style);
                    }
                }
            }
            else
            {
                styleProperty = style.GetType().GetRuntimeProperty(property.Name);
            }

            if (styleProperty == null)
            {
                return(false);
            }

            // Compare values
            var styleValue = styleProperty.GetValue(style);
            var value      = property.GetValue(w);

            if (!Equals(styleValue, value))
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        private static bool HasStylesheetValue(Widget w, PropertyInfo property, Stylesheet stylesheet)
        {
            if (stylesheet == null)
            {
                return(false);
            }

            var styleName = w.StyleName;

            if (string.IsNullOrEmpty(styleName))
            {
                styleName = Stylesheet.DefaultStyleName;
            }

            // Find styles dict of that widget
            var typeName = w.GetType().Name;

            if (typeName == "ImageTextButton" || typeName == "ImageButton" || typeName == "TextButton")
            {
                // Small hack
                // ImageTextButton styles are stored in Stylesheet.ButtonStyles
                typeName = "Button";
            }

            var stylesDictPropertyName = typeName + "Styles";
            var stylesDictProperty     = stylesheet.GetType().GetRuntimeProperty(stylesDictPropertyName);

            if (stylesDictProperty == null)
            {
                return(false);
            }

            var stylesDict = (IDictionary)stylesDictProperty.GetValue(stylesheet);

            if (stylesDict == null)
            {
                return(false);
            }

            // Fetch style from the dict
            if (!stylesDict.Contains(styleName))
            {
                styleName = Stylesheet.DefaultStyleName;
            }

            object obj = stylesDict[styleName];

            // Now find corresponding property
            PropertyInfo styleProperty = null;

            var stylePropertyPathAttribute = property.FindAttribute <StylePropertyPathAttribute>();

            if (stylePropertyPathAttribute != null)
            {
                var path = stylePropertyPathAttribute.Name;
                if (path.StartsWith("/"))
                {
                    obj  = stylesheet;
                    path = path.Substring(1);
                }

                var parts = path.Split('/');
                for (var i = 0; i < parts.Length; ++i)
                {
                    styleProperty = obj.GetType().GetRuntimeProperty(parts[i]);

                    if (i < parts.Length - 1)
                    {
                        obj = styleProperty.GetValue(obj);
                    }
                }
            }
            else
            {
                styleProperty = obj.GetType().GetRuntimeProperty(property.Name);
            }

            if (styleProperty == null)
            {
                return(false);
            }

            // Compare values
            var styleValue = styleProperty.GetValue(obj);
            var value      = property.GetValue(w);

            if (!Equals(styleValue, value))
            {
                return(false);
            }

            return(true);
        }