public static DataFieldMapping CreateDataFieldMapping(PropertyInfo property, DataFieldMapperConfig config, int positionOrder, DataMapping mapping) { var type = property.PropertyType; var typeInfo = type.GetTypeInfo(); var indexName = property.Name; var fieldName = string.IsNullOrEmpty(config.Name) ? property.Name : config.Name; DataFieldMapping fieldMapping; if (typeInfo.IsGenericType) { var frameType = type.GetGenericTypeDefinition(); if (frameType.FullName == "System.Nullable`1") { var arguments = typeInfo.GetGenericArguments(); type = arguments[0]; typeInfo = type.GetTypeInfo(); } } if (type.IsArray) { if (type.FullName == "System.Byte[]") { fieldMapping = new BytesFieldMapping(fieldName, indexName, mapping, config.IsNullable, config.DbType, config.IsIdentity, config.IsPrimaryKey); } else { fieldMapping = new ObjectFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType, config.IsIdentity, config.IsPrimaryKey); } } // else if (type.IsGenericParameter || typeInfo.IsGenericTypeDefinition) // { // throw new LightDataException(string.Format(SR.DataMappingUnsupportFieldType, property.DeclaringType, // property.Name, type)); // } else if (type == typeof(Guid)) { fieldMapping = new GuidFieldMapping(fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue, config.IsIdentity, config.IsPrimaryKey); } else if (type == typeof(string)) { fieldMapping = new StringFieldMapping(fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue, config.IsIdentity, config.IsPrimaryKey); } else if (type == typeof(DateTime)) { fieldMapping = new DateTimeFieldMapping(fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue, config.IsIdentity, config.IsPrimaryKey); } else if (type == typeof(decimal)) { fieldMapping = new DecimalFieldMapping(fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue, config.IsIdentity, config.IsPrimaryKey); } else if (typeInfo.IsEnum) { fieldMapping = new EnumFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue, config.IsIdentity, config.IsPrimaryKey); } else if (type.IsPrimitive) { fieldMapping = new PrimitiveFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue, config.IsIdentity, config.IsPrimaryKey); } else if (type == typeof(DBNull)) { throw new LightDataException(string.Format(SR.DataMappingUnsupportFieldType, property.DeclaringType, property.Name, type)); } else { fieldMapping = new ObjectFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType, config.IsIdentity, config.IsPrimaryKey); } if (config.DataOrder > 0) { fieldMapping.DataOrder = config.DataOrder; } fieldMapping.PositionOrder = positionOrder; fieldMapping.FunctionControl = config.FunctionControl == FunctionControl.Default ? FunctionControl.Full : config.FunctionControl; fieldMapping.Handler = new PropertyHandler(property); return(fieldMapping); }
public static DataFieldMapping CreateCustomFieldMapping(PropertyInfo property, DataMapping mapping) { Type type = property.PropertyType; TypeInfo typeInfo = type.GetTypeInfo(); string indexName = property.Name; string fieldName = property.Name; DataFieldMapping fieldMapping; string dbType = null; bool isNullable = false; if (typeInfo.IsGenericType) { Type frameType = type.GetGenericTypeDefinition(); if (frameType.FullName == "System.Nullable`1") { Type[] arguments = typeInfo.GetGenericArguments(); type = arguments[0]; typeInfo = type.GetTypeInfo(); isNullable = true; } } if (type.IsArray) { if (type.FullName == "System.Byte[]") { BytesFieldMapping bytesFieldMapping = new BytesFieldMapping(type, fieldName, indexName, mapping, isNullable, null); fieldMapping = bytesFieldMapping; } else { return(null); } } else if (type.IsGenericParameter || typeInfo.IsGenericTypeDefinition) { return(null); } else if (typeInfo.IsEnum) { EnumFieldMapping enumFieldMapping = new EnumFieldMapping(type, fieldName, indexName, mapping, isNullable); fieldMapping = enumFieldMapping; } else { TypeCode code = Type.GetTypeCode(type); if (code == TypeCode.Empty) { return(null); } else if (code == TypeCode.Object) { ObjectFieldMapping objectFieldMapping = new ObjectFieldMapping(type, fieldName, indexName, mapping, isNullable, dbType); fieldMapping = objectFieldMapping; } else { PrimitiveFieldMapping primitiveFieldMapping = new PrimitiveFieldMapping(type, fieldName, indexName, mapping, isNullable, dbType, null, false, false); fieldMapping = primitiveFieldMapping; } } fieldMapping._handler = new PropertyHandler(property); return(fieldMapping); }
public static DataFieldMapping CreateCustomFieldMapping(PropertyInfo property, DataMapping mapping) { var type = property.PropertyType; var typeInfo = type.GetTypeInfo(); var indexName = property.Name; var fieldName = property.Name; DataFieldMapping fieldMapping; var isNullable = false; if (typeInfo.IsGenericType) { var frameType = type.GetGenericTypeDefinition(); if (frameType.FullName == "System.Nullable`1") { var arguments = typeInfo.GetGenericArguments(); type = arguments[0]; typeInfo = type.GetTypeInfo(); isNullable = true; } } if (type.IsArray) { if (type.FullName == "System.Byte[]") { fieldMapping = new BytesFieldMapping(fieldName, indexName, mapping, isNullable, null, false, false); } else { fieldMapping = new ObjectFieldMapping(type, fieldName, indexName, mapping, isNullable, null, false, false); } } else if (type == typeof(Guid)) { fieldMapping = new GuidFieldMapping(fieldName, indexName, mapping, isNullable, null, null, false, false); } else if (type == typeof(string)) { fieldMapping = new StringFieldMapping(fieldName, indexName, mapping, isNullable, null, null, false, false); } else if (type == typeof(DateTime)) { fieldMapping = new DateTimeFieldMapping(fieldName, indexName, mapping, isNullable, null, null, false, false); } else if (type == typeof(decimal)) { fieldMapping = new DecimalFieldMapping(fieldName, indexName, mapping, isNullable, null, null, false, false); } else if (typeInfo.IsEnum) { fieldMapping = new EnumFieldMapping(type, fieldName, indexName, mapping, isNullable, null, null, false, false); } else if (type.IsPrimitive) { fieldMapping = new PrimitiveFieldMapping(type, fieldName, indexName, mapping, isNullable, null, null, false, false); } else if (type == typeof(DBNull)) { throw new LightDataException(string.Format(SR.DataMappingUnsupportFieldType, property.DeclaringType, property.Name, type)); } else { fieldMapping = new ObjectFieldMapping(type, fieldName, indexName, mapping, isNullable, null, false, false); } fieldMapping.Handler = new PropertyHandler(property); return(fieldMapping); }
public static DataFieldMapping CreateDataFieldMapping(PropertyInfo property, DataFieldMapperConfig config, int positionOrder, DataMapping mapping) { Type type = property.PropertyType; TypeInfo typeInfo = type.GetTypeInfo(); string indexName = property.Name; string fieldName = string.IsNullOrEmpty(config.Name) ? property.Name : config.Name; //if (!Regex.IsMatch(fieldName, _fieldRegex, RegexOptions.IgnoreCase)) { // throw new LightDataException(string.Format(SR.FieldNameIsInvalid, type, fieldName)); //} DataFieldMapping fieldMapping; if (typeInfo.IsGenericType) { Type frameType = type.GetGenericTypeDefinition(); if (frameType.FullName == "System.Nullable`1") { Type[] arguments = typeInfo.GetGenericArguments(); type = arguments[0]; typeInfo = type.GetTypeInfo(); } } if (type.IsArray) { if (type.FullName == "System.Byte[]") { BytesFieldMapping bytesFieldMapping = new BytesFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType); fieldMapping = bytesFieldMapping; } else { throw new LightDataException(string.Format(SR.DataMappingUnsupportFieldType, property.DeclaringType, property.Name, type)); } } else if (type.IsGenericParameter || typeInfo.IsGenericTypeDefinition) { throw new LightDataException(string.Format(SR.DataMappingUnsupportFieldType, property.DeclaringType, property.Name, type)); } else if (typeInfo.IsEnum) { EnumFieldMapping enumFieldMapping = new EnumFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue); fieldMapping = enumFieldMapping; } else { TypeCode code = Type.GetTypeCode(type); if (code == TypeCode.Empty) { throw new LightDataException(string.Format(SR.DataMappingUnsupportFieldType, property.DeclaringType, property.Name, type)); } else if (code == TypeCode.Object) { ObjectFieldMapping objectFieldMapping = new ObjectFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType); fieldMapping = objectFieldMapping; } else { PrimitiveFieldMapping primitiveFieldMapping = new PrimitiveFieldMapping(type, fieldName, indexName, mapping, config.IsNullable, config.DbType, config.DefaultValue, config.IsIdentity, config.IsPrimaryKey); fieldMapping = primitiveFieldMapping; } } if (config.DataOrder > 0) { fieldMapping._dataOrder = config.DataOrder; } fieldMapping._positionOrder = positionOrder; fieldMapping._functionControl = config.FunctionControl == FunctionControl.Default ? FunctionControl.Full : config.FunctionControl; fieldMapping._handler = new PropertyHandler(property); return(fieldMapping); }