Ejemplo n.º 1
0
        private MyPropInfo CreateMyProp(Type t, string name)
        {
            var d     = new MyPropInfo();
            var dType = MyPropInfoType.Unknown;

            //Debug.Log(name + ": " + t);
            if (t == typeof(int) || t == typeof(int?))
            {
                dType = MyPropInfoType.Int;
            }
            else if (t == typeof(long) || t == typeof(long?))
            {
                dType = MyPropInfoType.Long;
            }

            else if (t == typeof(float) || t == typeof(float?))
            {
                dType = MyPropInfoType.Float;
            }
            else if (t == typeof(char) || t == typeof(char?))
            {
                dType = MyPropInfoType.Char;
            }
            else if (t == typeof(byte) || t == typeof(byte?))
            {
                dType = MyPropInfoType.Byte;
            }
            else if (t == typeof(decimal) || t == typeof(decimal?))
            {
                dType = MyPropInfoType.Decimal;
            }
            else if (t == typeof(double) || t == typeof(double?))
            {
                dType = MyPropInfoType.Double;
            }
            else if (t == typeof(short) || t == typeof(short?))
            {
                dType = MyPropInfoType.Short;
            }

            else if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List <>))
            {
                dType = MyPropInfoType.List;
            }

            else if (t == typeof(string))
            {
                dType = MyPropInfoType.String;
            }
            else if (t == typeof(bool) || t == typeof(bool?))
            {
                dType = MyPropInfoType.Bool;
            }
            else if (t == typeof(DateTime) || t == typeof(DateTime?))
            {
                dType = MyPropInfoType.DateTime;
            }
            else if (t.IsEnum)
            {
                dType = MyPropInfoType.Enum;
            }
            else if (t == typeof(Guid) || t == typeof(Guid?))
            {
                dType = MyPropInfoType.Guid;
            }
            else if (t == typeof(StringDictionary))
            {
                dType = MyPropInfoType.StringDictionary;
            }
            else if (t == typeof(NameValueCollection))
            {
                dType = MyPropInfoType.NameValue;
            }
            else if (t.IsArray)
            {
                d.Bt  = t.GetElementType();
                dType = t == typeof(byte[]) ? MyPropInfoType.ByteArray : MyPropInfoType.Array;
            }
            else if (t.Name.Contains("Dictionary"))
            {
                d.GenericTypes = Instance.GetGenericArguments(t);
                if (d.GenericTypes.Length > 0 && d.GenericTypes[0] == typeof(string))
                {
                    dType = MyPropInfoType.StringKeyDictionary;
                }
                else
                {
                    dType = MyPropInfoType.Dictionary;
                }
            }
            else if (t == typeof(Hashtable))
            {
                dType = MyPropInfoType.Hashtable;
            }

            #region Unity_Build-in_Classes

            else if (t == typeof(Vector2))
            {
                dType = MyPropInfoType.Vector2;
            }
            else if (t == typeof(Vector2Int))
            {
                dType = MyPropInfoType.Vector2Int;
            }
            else if (t == typeof(Vector3))
            {
                dType = MyPropInfoType.Vector3;
            }
            else if (t == typeof(Vector3Int))
            {
                dType = MyPropInfoType.Vector3Int;
            }
            else if (t == typeof(Vector4))
            {
                dType = MyPropInfoType.Vector4;
            }

            else if (t == typeof(Color))
            {
                dType = MyPropInfoType.Color;
            }
            else if (t == typeof(Color32))
            {
                dType = MyPropInfoType.Color32;
            }

            else if (t == typeof(Rect))
            {
                dType = MyPropInfoType.Rect;
            }
            else if (t == typeof(RectInt))
            {
                dType = MyPropInfoType.RectInt;
            }

            else if (t == typeof(Bounds))
            {
                dType = MyPropInfoType.Bounds;
            }
            else if (t == typeof(BoundsInt))
            {
                dType = MyPropInfoType.BoundsInt;
            }

            else if (t == typeof(Quaternion))
            {
                dType = MyPropInfoType.Quaternion;
            }
            else if (t == typeof(Ray))
            {
                dType = MyPropInfoType.Ray;
            }
            else if (t == typeof(Ray2D))
            {
                dType = MyPropInfoType.Ray2D;
            }

            #endregion

            else if (IsTypeRegistered(t))
            {
                dType = MyPropInfoType.Custom;
            }

            if (t.IsValueType && !t.IsPrimitive && !t.IsEnum && t != typeof(decimal))
            {
                d.IsStruct = true;
            }

            d.IsInterface = t.IsInterface;
            d.IsClass     = t.IsClass;
            d.IsValueType = t.IsValueType;
            if (t.IsGenericType)
            {
                d.IsGenericType = true;
                d.Bt            = t.GetGenericArguments()[0];
            }

            d.Pt         = t;
            d.Name       = name;
            d.ChangeType = GetChangeType(t);
            d.Type       = dType;

            return(d);
        }
Ejemplo n.º 2
0
        private MyPropInfo CreateMyProp(Type t, string name)
        {
            var d      = new MyPropInfo();
            var d_type = MyPropInfoType.Unknown;

            if (t == typeof(int) || t == typeof(int?))
            {
                d_type = MyPropInfoType.Int;
            }
            else if (t == typeof(long) || t == typeof(long?))
            {
                d_type = MyPropInfoType.Long;
            }
            else if (t == typeof(string))
            {
                d_type = MyPropInfoType.String;
            }
            else if (t == typeof(bool) || t == typeof(bool?))
            {
                d_type = MyPropInfoType.Bool;
            }
            else if (t == typeof(DateTime) || t == typeof(DateTime?))
            {
                d_type = MyPropInfoType.DateTime;
            }
            else if (t.IsEnum)
            {
                d_type = MyPropInfoType.Enum;
            }
            else if (t == typeof(Guid) || t == typeof(Guid?))
            {
                d_type = MyPropInfoType.Guid;
            }
            else if (t == typeof(StringDictionary))
            {
                d_type = MyPropInfoType.StringDictionary;
            }
            else if (t == typeof(NameValueCollection))
            {
                d_type = MyPropInfoType.NameValue;
            }
            else if (t.IsArray)
            {
                d.bt = t.GetElementType();
                if (t == typeof(byte[]))
                {
                    d_type = MyPropInfoType.ByteArray;
                }
                else
                {
                    d_type = MyPropInfoType.Array;
                }
            }
            else if (t.Name.Contains("Dictionary"))
            {
                d.GenericTypes = Reflection.Instance.GetGenericArguments(t);
                if (d.GenericTypes.Length > 0 && d.GenericTypes[0] == typeof(string))
                {
                    d_type = MyPropInfoType.StringKeyDictionary;
                }
                else
                {
                    d_type = MyPropInfoType.Dictionary;
                }
            }
            else if (t == typeof(Hashtable))
            {
                d_type = MyPropInfoType.Hashtable;
            }
            //else if (t == typeof(DataSet)) d_type = MyPropInfoType.DataSet;
            //else if (t == typeof(DataTable)) d_type = MyPropInfoType.DataTable;
            else if (IsTypeRegistered(t))
            {
                d_type = MyPropInfoType.Custom;
            }

            if (t.IsValueType && !t.IsPrimitive && !t.IsEnum && t != typeof(decimal))
            {
                d.IsStruct = true;
            }

            d.IsInterface = t.IsInterface;
            d.IsClass     = t.IsClass;
            d.IsValueType = t.IsValueType;
            if (t.IsGenericType)
            {
                d.IsGenericType = true;
                d.bt            = Reflection.Instance.GetGenericArguments(t)[0];
            }

            d.pt         = t;
            d.Name       = name;
            d.changeType = GetChangeType(t);
            d.Type       = d_type;

            return(d);
        }