コード例 #1
0
ファイル: Reflection.cs プロジェクト: crazyants/ZidiumServer
        private myPropInfo CreateMyProp(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.GetTypeInfo().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;
            }
#endif
            else if (customType)
            {
                d_type = myPropInfoType.Custom;
            }

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

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

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

            return(d);
        }