public static DataFieldMapperConfig LoadDataFieldConfig(Type type, PropertyInfo pi) { if (DataMapperConfiguration.TryGetDataFieldConfig(type, pi.Name, out var mapperConfig)) { return(mapperConfig); } var attributes = AttributeCore.GetPropertyAttributes <DataFieldAttribute>(pi, true); if (attributes.Length > 0) { var attribute = attributes[0]; var config = new DataFieldMapperConfig(pi.Name) { Name = attribute.Name, IsPrimaryKey = attribute.IsPrimaryKey, IsNullable = attribute.IsNullable, IsIdentity = attribute.IsIdentity, DefaultValue = attribute.DefaultValue, DbType = attribute.DbType, DataOrder = attribute.DataOrder, FunctionControl = attribute.FunctionControl }; return(config); } return(null); }
public static RelationFieldMapConfig LoadRelationDataFieldConfig(Type type, PropertyInfo pi) { if (DataMapperConfiguration.TryGetRelateFieldConfig(type, pi.Name, out var mapperConfig)) { return(mapperConfig); } var relationAttributes = AttributeCore.GetPropertyAttributes <RelationFieldAttribute>(pi, true); if (relationAttributes.Length > 0) { var rfConfig = new RelationFieldMapConfig(pi.Name); foreach (var ra in relationAttributes) { rfConfig.AddRelationKeys(ra.MasterKey, ra.RelateKey); } return(rfConfig); } return(null); }
public static DataParameter[] ConvertParameter(object data) { if (data == null) { return(null); } var type = data.GetType(); if (!TypeDict.TryGetValue(type, out var mappings)) { lock (TypeDict) { if (!TypeDict.TryGetValue(type, out mappings)) { var typeInfo = type.GetTypeInfo(); var properties = typeInfo.GetProperties(BindingFlags.Instance | BindingFlags.Public); var list = new List <DataParameterMapping>(); foreach (var property in properties) { string name = null; var direction = ParameterDirection.Input; var attributes = AttributeCore.GetPropertyAttributes <DataParameterAttribute>(property, true); if (attributes.Length > 0) { var attribute = attributes[0]; name = attribute.Name; direction = attribute.Direction; } var mapping = new DataParameterMapping(property, name, direction); list.Add(mapping); } mappings = list.ToArray(); TypeDict.Add(type, mappings); } } } if (mappings.Length == 0) { return(null); } var dataParameters = new DataParameter[mappings.Length]; for (var i = 0; i < mappings.Length; i++) { var mapping = mappings[i]; var value = mapping.Get(data); if (!Equals(value, null) && mapping.ConvertString) { value = value.ToString(); } var dataParameter = mapping.Direction != ParameterDirection.Input ? new CallbackDataParameter(mapping.Name, value, mapping.Direction, data, mapping) : new DataParameter(mapping.Name, value, mapping.Direction); dataParameters[i] = dataParameter; } return(dataParameters); }