private myPropInfo CreateMyProp(Type t, string name, bool customType) { 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(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; 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; }
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.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; } } 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]; } d.pt = t; d.Name = name; d.changeType = GetChangeType(t); d.Type = d_type; return(d); }
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.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 (typeof(IDictionary).IsAssignableFrom(t)) { 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 && !UNITY 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]; } d.pt = t; d.Name = name; d.changeType = GetChangeType(t); d.Type = d_type; return d; }
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); }
public Dictionary <string, myPropInfo> Getproperties(Type type, string typename, bool ShowReadOnlyProperties) { Dictionary <string, myPropInfo> sd = null; if (_propertycache.TryGetValue(typename, out sd)) { return(sd); } else { sd = new Dictionary <string, myPropInfo>(10); var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; PropertyInfo[] pr = type.GetProperties(bf); foreach (PropertyInfo p in pr) { if (p.GetIndexParameters().Length > 0)// Property is an indexer { continue; } myPropInfo d = CreateMyProp(p.PropertyType, p.Name); d.setter = Reflection.CreateSetMethod(type, p, ShowReadOnlyProperties); if (d.setter != null) { d.CanWrite = true; } d.getter = Reflection.CreateGetMethod(type, p); #if NET4 var att = p.GetCustomAttributes(true); foreach (var at in att) { if (at is DataMemberAttribute) { var dm = (DataMemberAttribute)at; if (dm.Name != "") { d.memberName = dm.Name; } } } if (d.memberName != null) { sd.Add(d.memberName, d); } else #endif sd.Add(p.Name.ToLowerInvariant(), d); } FieldInfo[] fi = type.GetFields(bf); foreach (FieldInfo f in fi) { myPropInfo d = CreateMyProp(f.FieldType, f.Name); if (f.IsLiteral == false) { if (f.IsInitOnly == false) { d.setter = Reflection.CreateSetField(type, f); } if (d.setter != null) { d.CanWrite = true; } d.getter = Reflection.CreateGetField(type, f); #if NET4 var att = f.GetCustomAttributes(true); foreach (var at in att) { if (at is DataMemberAttribute) { var dm = (DataMemberAttribute)at; if (dm.Name != "") { d.memberName = dm.Name; } } } if (d.memberName != null) { sd.Add(d.memberName, d); } else #endif sd.Add(f.Name.ToLowerInvariant(), d); } } _propertycache.Add(typename, sd); return(sd); } }
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.Convert().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 NET4 else if (t.IsAssignableFrom(typeof(DynamicJson))) { d_type = myPropInfoType.Dynamic; } #endif var tr = t.Convert(); if (tr.IsValueType && !tr.IsPrimitive && !tr.IsEnum && t != typeof(decimal)) { d.IsStruct = true; } d.IsInterface = tr.IsInterface; d.IsClass = tr.IsClass; d.IsValueType = tr.IsValueType; if (tr.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); }
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.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 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); }
private myPropInfo CreateMyProp(Type t, string name) { myPropInfo d = new myPropInfo(); d.filled = true; d.CanWrite = true; d.pt = t; d.Name = name; int nIndex = -1; nIndex = t.Name.IndexOf("Dictionary"); if (nIndex >= 0) { d.isDictionary = true; } else { d.isDictionary = false; } //d.isDictionary = t.Name.Contains("Dictionary"); if (d.isDictionary) { d.GenericTypes = t.GetGenericArguments(); } d.isValueType = t.IsValueType; d.isGenericType = t.IsGenericType; d.isArray = t.IsArray; if (d.isArray) { d.bt = t.GetElementType(); } if (d.isGenericType) { d.bt = t.GetGenericArguments()[0]; } d.isByteArray = t == typeof(byte[]); d.isGuid = (t == typeof(Guid) || t == typeof(Guid?)); #if !SILVERLIGHT d.isHashtable = t == typeof(Hashtable); d.isDataSet = t == typeof(DataSet); d.isDataTable = t == typeof(DataTable); #endif d.changeType = GetChangeType(t); d.isEnum = t.IsEnum; d.isDateTime = t == typeof(DateTime) || t == typeof(DateTime?); d.isInt = t == typeof(int) || t == typeof(int?); d.isLong = t == typeof(long) || t == typeof(long?); d.isString = t == typeof(string); d.isBool = t == typeof(bool) || t == typeof(bool?); d.isClass = t.IsClass; if (d.isDictionary && d.GenericTypes.Length > 0 && d.GenericTypes[0] == typeof(string)) { d.isStringDictionary = true; } #if CUSTOMTYPE if (IsTypeRegistered(t)) { d.isCustomType = true; } #endif return(d); }
public Dictionary <string, myPropInfo> Getproperties(Type type, string typename, bool customType) { Dictionary <string, myPropInfo> sd = null; if (_propertycache.TryGetValue(typename, out sd)) { return(sd); } else { sd = new Dictionary <string, myPropInfo>(); PropertyInfo[] pr = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); foreach (PropertyInfo p in pr) { bool pass = false; foreach (var attrtype in JSON.Parameters.IgnoreAttributes) { if (p.IsDefined(attrtype, true)) { pass = true; break; } } if (pass) { continue; } if (p.GetIndexParameters().Length > 0) {// Property is an indexer continue; } myPropInfo d = CreateMyProp(p.PropertyType, p.Name, customType); d.setter = Reflection.CreateSetMethod(type, p); if (d.setter != null && p.CanWrite) { d.CanWrite = true; } d.getter = Reflection.CreateGetMethod(type, p); sd.Add(p.Name.ToLower(), d); } FieldInfo[] fi = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); foreach (FieldInfo f in fi) { myPropInfo d = CreateMyProp(f.FieldType, f.Name, customType); if (f.IsLiteral == false) { d.setter = Reflection.CreateSetField(type, f); if (d.setter != null) { d.CanWrite = true; } d.getter = Reflection.CreateGetField(type, f); sd.Add(f.Name.ToLower(), d); } } _propertycache.Add(typename, sd); return(sd); } }
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); }