Пример #1
0
        /// <summary>
        /// Creates style property from StyleAttribute
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static MediaQuery FromAttribute(StyleAttribute attribute)
        {
            var value = attribute.GetDefault();

            /**
             * 1. If the value is a skin class, we should switch to string type
             * because we cannot serialize the type
             * Hopwever, both type and string are valid for skin class
             * */
            if (value is Type)
            {
                var type = (Type)value;
                if (typeof(Skin).IsAssignableFrom(type))
                {
                    /*if (null != value)
                    attribute.Type = value.GetType(); // default*/

                    attribute.Type = typeof(string); // we cannot serialize type, so switching to string
                    value = type.FullName; // using string instead (full id as default value)
                }
            }

            var prop = CreateProperty<MediaQuery>(attribute.Name, attribute.Type);
            //prop.Name = attribute.Name;

            /**
             * We cannot serialize GUIStyle generated from code as object reference
             * */
            if (null != value)
            {
                prop.Value = value;
            }

            return (MediaQuery) prop;
        }
Пример #2
0
        private void ValidateAttribute(StyleAttribute attribute)
        {
            if (0 == attribute.Name.Length)
                throw new Exception(string.Format("Name not defined in Style attribute [class {0}]", _componentType));

            if (null == attribute.Type && attribute.Name != "skinClass")
                throw new Exception(string.Format(@"Type not defined in Style attribute [style ""{0}"", class {1}]", attribute.Name, _componentType));

            /* XOR! */
            //if ((null == attribute.ProxyType) ^ (0 == attribute.ProxyMemberName.Length)) {
            //    //Debug.Log("attribute.ProxyType: " + attribute.ProxyType);
            //    //Debug.Log("attribute.ProxyMemberName: " + attribute.ProxyMemberName);
            //    throw new Exception(string.Format(@"When using proxy in the Style attribute, both ProxyType and ProxyMemberName have to be defined in Style attribute [style ""{0}"", class {1}]", attribute.Name, _componentType));
            //}

//            /* XOR! */
//            if (null == attribute.ProxyType && !string.IsNullOrEmpty(attribute.ProxyMemberName) ||
//                null != attribute.ProxyType && string.IsNullOrEmpty(attribute.ProxyMemberName))
//                throw new Exception(string.Format("When using proxy in the Style attribute, both ProxyType and ProxyMemberName have to be defined in Style attribute [{0}], class {1}", attribute.Name, _componentType));
        }
Пример #3
0
        private void ValidateAttribute(StyleAttribute attribute)
        {
            if (0 == attribute.Name.Length)
            {
                throw new Exception(string.Format("Name not defined in Style attribute [class {0}]", _componentType));
            }

            if (null == attribute.Type && attribute.Name != "skinClass")
            {
                throw new Exception(string.Format(@"Type not defined in Style attribute [style ""{0}"", class {1}]", attribute.Name, _componentType));
            }

            /* XOR! */
            //if ((null == attribute.ProxyType) ^ (0 == attribute.ProxyMemberName.Length)) {
            //    //Debug.Log("attribute.ProxyType: " + attribute.ProxyType);
            //    //Debug.Log("attribute.ProxyMemberName: " + attribute.ProxyMemberName);
            //    throw new Exception(string.Format(@"When using proxy in the Style attribute, both ProxyType and ProxyMemberName have to be defined in Style attribute [style ""{0}"", class {1}]", attribute.Name, _componentType));
            //}

//            /* XOR! */
//            if (null == attribute.ProxyType && !string.IsNullOrEmpty(attribute.ProxyMemberName) ||
//                null != attribute.ProxyType && string.IsNullOrEmpty(attribute.ProxyMemberName))
//                throw new Exception(string.Format("When using proxy in the Style attribute, both ProxyType and ProxyMemberName have to be defined in Style attribute [{0}], class {1}", attribute.Name, _componentType));
        }
Пример #4
0
        /// <summary>
        /// Creates style property from StyleAttribute
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static MediaQuery FromAttribute(StyleAttribute attribute)
        {
            var value = attribute.GetDefault();

            /**
             * 1. If the value is a skin class, we should switch to string type
             * because we cannot serialize the type
             * Hopwever, both type and string are valid for skin class
             * */
            if (value is Type)
            {
                var type = (Type)value;
                if (typeof(Skin).IsAssignableFrom(type))
                {
                    /*if (null != value)
                     * attribute.Type = value.GetType(); // default*/

                    attribute.Type = typeof(string); // we cannot serialize type, so switching to string
                    value          = type.FullName;  // using string instead (full id as default value)
                }
            }

            var prop = CreateProperty <MediaQuery>(attribute.Name, attribute.Type);

            //prop.Name = attribute.Name;

            /**
             * We cannot serialize GUIStyle generated from code as object reference
             * */
            if (null != value)
            {
                prop.Value = value;
            }

            return((MediaQuery)prop);
        }
Пример #5
0
 private static int StyleSort(StyleAttribute x, StyleAttribute y)
 {
     return String.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase);
 }