예제 #1
0
        private myPropInfo CreateMyProp(Type t, string name)
        {
            myPropInfo     d      = new myPropInfo();
            myPropInfoType 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;
                }
            }
#if !SILVERLIGHT
            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;
            }
#endif
            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            = t.GetGenericArguments()[0];
            }

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

            return(d);
        }
예제 #2
0
        private myPropInfo CreateMyProp(Type t, string name, bool customType)
        {
            myPropInfo      info    = new myPropInfo();
            myPropInfoType  unknown = myPropInfoType.Unknown;
            myPropInfoFlags flags   = myPropInfoFlags.CanWrite | myPropInfoFlags.Filled;

            if ((t == typeof(int)) || (t == typeof(int?)))
            {
                unknown = myPropInfoType.Int;
            }
            else if ((t == typeof(long)) || (t == typeof(long?)))
            {
                unknown = myPropInfoType.Long;
            }
            else if (t == typeof(string))
            {
                unknown = myPropInfoType.String;
            }
            else if ((t == typeof(bool)) || (t == typeof(bool?)))
            {
                unknown = myPropInfoType.Bool;
            }
            else if ((t == typeof(DateTime)) || (t == typeof(DateTime?)))
            {
                unknown = myPropInfoType.DateTime;
            }
            else if (t.IsEnum)
            {
                unknown = myPropInfoType.Enum;
            }
            else if ((t == typeof(Guid)) || (t == typeof(Guid?)))
            {
                unknown = myPropInfoType.Guid;
            }
            else if (t == typeof(StringDictionary))
            {
                unknown = myPropInfoType.StringDictionary;
            }
            else if (t == typeof(NameValueCollection))
            {
                unknown = myPropInfoType.NameValue;
            }
            else if (t.IsArray)
            {
                info.bt = t.GetElementType();
                if (t == typeof(byte[]))
                {
                    unknown = myPropInfoType.ByteArray;
                }
                else
                {
                    unknown = myPropInfoType.Array;
                }
            }
            else if (t.Name.Contains("Dictionary"))
            {
                info.GenericTypes = Instance.GetGenericArguments(t);
                if ((info.GenericTypes.Length > 0) && (info.GenericTypes[0] == typeof(string)))
                {
                    unknown = myPropInfoType.StringKeyDictionary;
                }
                else
                {
                    unknown = myPropInfoType.Dictionary;
                }
            }
            else if (t == typeof(Hashtable))
            {
                unknown = myPropInfoType.Hashtable;
            }
            else if (customType)
            {
                unknown = myPropInfoType.Custom;
            }
            info.IsClass     = t.IsClass;
            info.IsValueType = t.IsValueType;
            if (t.IsGenericType)
            {
                info.IsGenericType = true;
                info.bt            = t.GetGenericArguments()[0];
            }
            info.pt         = t;
            info.Name       = name;
            info.changeType = this.GetChangeType(t);
            info.Type       = unknown;
            info.Flags      = flags;
            return(info);
        }
예제 #3
0
        private myPropInfo CreateMyProp(Type t, string name)
        {
            myPropInfo      d       = new myPropInfo();
            myPropInfoType  d_type  = myPropInfoType.Unknown;
            myPropInfoFlags d_flags = myPropInfoFlags.Filled | myPropInfoFlags.CanWrite;

            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(short) || t == typeof(short?))
            {
                d_type = myPropInfoType.Short;
            }
            else if (t == typeof(float) || t == typeof(float?))
            {
                d_type = myPropInfoType.Float;
            }
            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 = t.GetGenericArguments();
                if (d.GenericTypes.Length > 0 && d.GenericTypes[0] == typeof(string))
                {
                    d_type = myPropInfoType.StringDictionary;
                }
                else
                {
                    d_type = myPropInfoType.Dictionary;
                }
            }
#if !SILVERLIGHT && ADONET
            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;
            }
#endif

            else if (IsTypeRegistered(t))
            {
                d_type = myPropInfoType.Custom;
            }

            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       = d_type;
            d.Flags      = d_flags;

            return(d);
        }
예제 #4
0
파일: Reflection.cs 프로젝트: xVir/fastJSON
        private myPropInfo CreateMyProp(MemberInfo memberInfo, Type t, string name, bool customType)
        {
            myPropInfo     d      = new myPropInfo();
            myPropInfoType 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);// t.GetGenericArguments();
                if (d.GenericTypes.Length > 0 && d.GenericTypes[0] == typeof(string))
                {
                    d_type = myPropInfoType.StringKeyDictionary;
                }
                else
                {
                    d_type = myPropInfoType.Dictionary;
                }
            }
#if !SILVERLIGHT
            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;
            }
#endif
            else if (customType)
            {
                d_type = myPropInfoType.Custom;
            }

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

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

            var jsonName = name;
            if (memberInfo.IsDefined(typeof(JsonPropertyAttribute), false))
            {
                var attr = memberInfo.GetCustomAttributes(typeof(JsonPropertyAttribute), false)[0] as JsonPropertyAttribute;
                if (!string.IsNullOrEmpty(attr.PropertyName))
                {
                    jsonName = attr.PropertyName;
                }
            }

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

            return(d);
        }