private void InitInfo(Type modelType) { accessorDict = new Dictionary <string, Accessor>(); var Properties = TypeCache.GetTable(modelType).Fields; foreach (var kv in Properties) { Accessor accessor = null; var prop = kv.GetPropertyInfo(); string propName = prop.Name.ToUpper(); var propType = prop.PropertyType; if (propType.IsEnum) { propType = propType.GetEnumUnderlyingType(); } if (typeof(string) == propType) { accessor = new StringAccessor(prop); } else if (typeof(int) == propType) { accessor = new IntAccessor(prop); } else if (typeof(int?) == propType) { accessor = new IntNullableAccessor(prop); } else if (typeof(DateTime) == propType) { accessor = new DateTimeAccessor(prop); } else if (typeof(DateTime?) == propType) { accessor = new DateTimeNullableAccessor(prop); } else if (typeof(long) == propType) { accessor = new LongAccessor(prop); } else if (typeof(long?) == propType) { accessor = new LongNullableAccessor(prop); } else if (typeof(float) == propType) { accessor = new FloatAccessor(prop); } else if (typeof(float?) == propType) { accessor = new FloatNullableAccessor(prop); } else if (typeof(double) == propType) { accessor = new DoubleAccessor(prop); } else if (typeof(double?) == propType) { accessor = new DoubleNullableAccessor(prop); } else if (typeof(Guid) == propType) { accessor = new GuidAccessor(prop); } else if (typeof(Guid?) == propType) { accessor = new GuidNullableAccessor(prop); } else if (typeof(short) == propType) { accessor = new ShortAccessor(prop); } else if (typeof(short?) == propType) { accessor = new ShortNullableAccessor(prop); } else if (typeof(byte) == propType) { accessor = new ByteAccessor(prop); } else if (typeof(byte?) == propType) { accessor = new ByteNullableAccessor(prop); } else if (typeof(char) == propType) { accessor = new CharAccessor(prop); } else if (typeof(char?) == propType) { accessor = new CharNullableAccessor(prop); } else if (typeof(decimal) == propType) { accessor = new DecimalAccessor(prop); } else if (typeof(decimal?) == propType) { accessor = new DecimalNullableAccessor(prop); } else if (typeof(byte[]) == propType) { accessor = new ByteArrayAccessor(prop); } else if (typeof(bool) == propType) { accessor = new BoolAccessor(prop); } else if (typeof(bool?) == propType) { accessor = new BoolNullableAccessor(prop); } else if (typeof(TimeSpan) == propType) { accessor = new TimeSpanAccessor(prop); } else if (typeof(TimeSpan?) == propType) { accessor = new TimeSpanNullableAccessor(prop); } accessorDict[propName] = accessor; } }
private void InitInfo() { accessorDict = new Dictionary <string, Accessor>(Properties.Length); FieldAttrDict = new Dictionary <PropertyInfo, OrmFieldAttribute>(Properties.Length); foreach (var prop in Properties) { Accessor accessor = null; string propName = prop.Name.ToUpper(); var propType = prop.PropertyType; if (propType.IsEnum) { propType = propType.GetEnumUnderlyingType(); } if (typeof(string) == propType) { accessor = new StringAccessor(prop); } else if (typeof(int) == propType) { accessor = new IntAccessor(prop); } else if (typeof(int?) == propType) { accessor = new IntNullableAccessor(prop); } else if (typeof(DateTime) == propType) { accessor = new DateTimeAccessor(prop); } else if (typeof(DateTime?) == propType) { accessor = new DateTimeNullableAccessor(prop); } else if (typeof(long) == propType) { accessor = new LongAccessor(prop); } else if (typeof(long?) == propType) { accessor = new LongNullableAccessor(prop); } else if (typeof(float) == propType) { accessor = new FloatAccessor(prop); } else if (typeof(float?) == propType) { accessor = new FloatNullableAccessor(prop); } else if (typeof(double) == propType) { accessor = new DoubleAccessor(prop); } else if (typeof(double?) == propType) { accessor = new DoubleNullableAccessor(prop); } else if (typeof(Guid) == propType) { accessor = new GuidAccessor(prop); } else if (typeof(Guid?) == propType) { accessor = new GuidNullableAccessor(prop); } else if (typeof(short) == propType) { accessor = new ShortAccessor(prop); } else if (typeof(short?) == propType) { accessor = new ShortNullableAccessor(prop); } else if (typeof(byte) == propType) { accessor = new ByteAccessor(prop); } else if (typeof(byte?) == propType) { accessor = new ByteNullableAccessor(prop); } else if (typeof(char) == propType) { accessor = new CharAccessor(prop); } else if (typeof(char?) == propType) { accessor = new CharNullableAccessor(prop); } else if (typeof(decimal) == propType) { accessor = new DecimalAccessor(prop); } else if (typeof(decimal?) == propType) { accessor = new DecimalNullableAccessor(prop); } else if (typeof(byte[]) == propType) { accessor = new ByteArrayAccessor(prop); } else if (typeof(bool) == propType) { accessor = new BoolAccessor(prop); } else if (typeof(bool?) == propType) { accessor = new BoolNullableAccessor(prop); } else if (typeof(TimeSpan) == propType) { accessor = new TimeSpanAccessor(prop); } else if (typeof(TimeSpan?) == propType) { accessor = new TimeSpanNullableAccessor(prop); } accessorDict[propName] = accessor; //自定义属性 var customerAttributes = prop.GetCustomAttributes(typeof(OrmFieldAttribute), false); if (customerAttributes == null || customerAttributes.Length == 0) { FieldAttrDict[prop] = null; } else { FieldAttrDict[prop] = (OrmFieldAttribute)customerAttributes[0]; } } }