private void InitialRelationField() { PropertyInfo[] propertys = ObjectTypeInfo.GetProperties(BindingFlags.Public | BindingFlags.Instance); List <CollectionRelationFieldMapping> collectionTmpList = new List <CollectionRelationFieldMapping>(); List <SingleRelationFieldMapping> singleTmpList = new List <SingleRelationFieldMapping>(); foreach (PropertyInfo pi in propertys) { RelationFieldMapConfig config = MapperConfigManager.LoadRelationDataFieldConfig(ObjectType, pi); if (config != null && config.RelationKeyCount > 0) { Type type = pi.PropertyType; TypeInfo typeInfo = type.GetTypeInfo(); if (typeInfo.IsGenericType) { Type frameType = type.GetGenericTypeDefinition(); if (frameType == LCollectionFrameType || frameType.FullName == "System.Collections.Generic.ICollection`1") { Type[] arguments = typeInfo.GetGenericArguments(); type = arguments[0]; PropertyHandler handler = new PropertyHandler(pi); RelationKey[] keypairs = config.GetRelationKeys(); CollectionRelationFieldMapping rmapping = new CollectionRelationFieldMapping(pi.Name, this, type, keypairs, handler); collectionTmpList.Add(rmapping); } } else { PropertyHandler handler = new PropertyHandler(pi); RelationKey[] keypairs = config.GetRelationKeys(); SingleRelationFieldMapping rmapping = new SingleRelationFieldMapping(pi.Name, this, type, keypairs, handler); singleTmpList.Add(rmapping); } } } _collectionRelationFields = new ReadOnlyCollection <CollectionRelationFieldMapping>(collectionTmpList); _singleRelationFields = new ReadOnlyCollection <SingleRelationFieldMapping>(singleTmpList); }
protected BaseRelationFieldMapping(string fieldName, DataEntityMapping mapping, Type relateType, RelationKey [] keyPairs, PropertyHandler handler) { if (fieldName == null) { throw new ArgumentNullException(nameof(fieldName)); } if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } if (relateType == null) { throw new ArgumentNullException(nameof(relateType)); } if (keyPairs == null || keyPairs.Length == 0) { throw new ArgumentNullException(nameof(keyPairs)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } this.fieldName = fieldName; this.masterEntityMapping = mapping; this.relateType = relateType; this.keyPairs = keyPairs; this.handler = handler; this.masterFieldMappings = new DataFieldMapping [keyPairs.Length]; this.masterInfos = new DataFieldInfo [keyPairs.Length]; for (int i = 0; i < keyPairs.Length; i++) { DataFieldMapping field = mapping.FindDataEntityField(keyPairs [i].MasterKey); if (field == null) { throw new LightDataException(string.Format(SR.CanNotFindTheSpecifiedField, mapping.ObjectType, keyPairs[i].MasterKey)); } this.masterFieldMappings [i] = field; this.masterInfos [i] = new DataFieldInfo(field); } }
public CollectionRelationFieldMapping(string fieldName, DataEntityMapping mapping, Type relateType, RelationKey[] keyPairs, PropertyHandler handler) : base(fieldName, mapping, relateType, keyPairs, handler) { }