[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // InitInheritedType method call. public MappedRootType(MappedMetaModel model, MappedTable table, TypeMapping typeMapping, Type type) : base(model, table, typeMapping, type, null) { if (typeMapping == null) { throw Error.ArgumentNull("typeMapping"); } if (typeMapping.InheritanceCode != null || typeMapping.DerivedTypes.Count > 0) { if (this.Discriminator == null) { throw Error.NoDiscriminatorFound(type.Name); } this.hasInheritance = true; if (!MappingSystem.IsSupportedDiscriminatorType(this.Discriminator.Type)) { throw Error.DiscriminatorClrTypeNotSupported(this.Discriminator.DeclaringType.Name, this.Discriminator.Name, this.Discriminator.Type); } this.derivedTypes = new Dictionary <Type, MetaType>(); this.inheritanceCodes = new Dictionary <object, MetaType>(); this.InitInheritedType(typeMapping, this); } if (this.inheritanceDefault == null && (this.InheritanceCode != null || this.inheritanceCodes != null && this.inheritanceCodes.Count > 0)) { throw Error.InheritanceHierarchyDoesNotDefineDefault(type); } if (this.derivedTypes != null) { this.inheritanceTypes = this.derivedTypes.Values.ToList().AsReadOnly(); } else { this.inheritanceTypes = new MetaType[] { this }.ToList().AsReadOnly(); } this.Validate(); }
[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // InitInheritedType method call. public MappedRootType(MappedMetaModel model, MappedTable table, TypeMapping typeMapping, Type type) : base(model, table, typeMapping, type, null) { if(typeMapping == null) throw Error.ArgumentNull("typeMapping"); if(typeMapping.InheritanceCode != null || typeMapping.DerivedTypes.Count > 0) { if(this.Discriminator == null) { throw Error.NoDiscriminatorFound(type.Name); } this.hasInheritance = true; if(!MappingSystem.IsSupportedDiscriminatorType(this.Discriminator.Type)) { throw Error.DiscriminatorClrTypeNotSupported(this.Discriminator.DeclaringType.Name, this.Discriminator.Name, this.Discriminator.Type); } this.derivedTypes = new Dictionary<Type, MetaType>(); this.inheritanceCodes = new Dictionary<object, MetaType>(); this.InitInheritedType(typeMapping, this); } if(this.inheritanceDefault == null && (this.InheritanceCode != null || this.inheritanceCodes != null && this.inheritanceCodes.Count > 0)) throw Error.InheritanceHierarchyDoesNotDefineDefault(type); if(this.derivedTypes != null) { this.inheritanceTypes = this.derivedTypes.Values.ToList().AsReadOnly(); } else { this.inheritanceTypes = new MetaType[] { this }.ToList().AsReadOnly(); } this.Validate(); }
[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // FindType method call. internal MappedFunction(MappedMetaModel model, FunctionMapping map, MethodInfo method) { this.model = model; this.map = map; this.method = method; this.rowTypes = _emptyTypes; if(map.Types.Count == 0 && this.method.ReturnType == typeof(IMultipleResults)) { throw Error.NoResultTypesDeclaredForFunction(method.Name); } else if(map.Types.Count > 1 && this.method.ReturnType != typeof(IMultipleResults)) { throw Error.TooManyResultTypesDeclaredForFunction(method.Name); } else if(map.Types.Count == 1 && this.method.ReturnType != typeof(IMultipleResults)) { Type elementType = TypeSystem.GetElementType(method.ReturnType); this.rowTypes = new List<MetaType>(1) { this.GetMetaType(map.Types[0], elementType) }.AsReadOnly(); } else if(map.Types.Count > 0) { List<MetaType> rowTypes = new List<MetaType>(); foreach(TypeMapping rtm in map.Types) { Type elementType = model.FindType(rtm.Name); if(elementType == null) { throw Error.CouldNotFindElementTypeInModel(rtm.Name); } MetaType mt = this.GetMetaType(rtm, elementType); // Only add unique meta types if(!rowTypes.Contains(mt)) { rowTypes.Add(mt); } } this.rowTypes = rowTypes.AsReadOnly(); } else if(map.FunReturn != null) { this.returnParameter = new MappedReturnParameter(method.ReturnParameter, map.FunReturn); } // Parameters. ParameterInfo[] pis = this.method.GetParameters(); if(pis.Length > 0) { List<MetaParameter> mps = new List<MetaParameter>(pis.Length); if(this.map.Parameters.Count != pis.Length) { throw Error.IncorrectNumberOfParametersMappedForMethod(this.map.MethodName); } for(int i = 0; i < pis.Length; i++) { mps.Add(new MappedParameter(pis[i], this.map.Parameters[i])); } this.parameters = mps.AsReadOnly(); } else { this.parameters = _emptyParameters; } }
[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // MappedRootType constructor call. internal MappedTable(MappedMetaModel model, TableMapping mapping, Type rowType) { this.model = model; this.mapping = mapping; this.rowType = new MappedRootType(model, this, mapping.RowType, rowType); }
[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // FindType method call. internal MappedFunction(MappedMetaModel model, FunctionMapping map, MethodInfo method) { this.model = model; this.map = map; this.method = method; this.rowTypes = _emptyTypes; if (map.Types.Count == 0 && this.method.ReturnType == typeof(IMultipleResults)) { throw Error.NoResultTypesDeclaredForFunction(method.Name); } else if (map.Types.Count > 1 && this.method.ReturnType != typeof(IMultipleResults)) { throw Error.TooManyResultTypesDeclaredForFunction(method.Name); } else if (map.Types.Count == 1 && this.method.ReturnType != typeof(IMultipleResults)) { Type elementType = TypeSystem.GetElementType(method.ReturnType); this.rowTypes = new List <MetaType>(1) { this.GetMetaType(map.Types[0], elementType) }.AsReadOnly(); } else if (map.Types.Count > 0) { List <MetaType> rowTypes = new List <MetaType>(); foreach (TypeMapping rtm in map.Types) { Type elementType = model.FindType(rtm.Name); if (elementType == null) { throw Error.CouldNotFindElementTypeInModel(rtm.Name); } MetaType mt = this.GetMetaType(rtm, elementType); // Only add unique meta types if (!rowTypes.Contains(mt)) { rowTypes.Add(mt); } } this.rowTypes = rowTypes.AsReadOnly(); } else if (map.FunReturn != null) { this.returnParameter = new MappedReturnParameter(method.ReturnParameter, map.FunReturn); } // Parameters. ParameterInfo[] pis = this.method.GetParameters(); if (pis.Length > 0) { List <MetaParameter> mps = new List <MetaParameter>(pis.Length); if (this.map.Parameters.Count != pis.Length) { throw Error.IncorrectNumberOfParametersMappedForMethod(this.map.MethodName); } for (int i = 0; i < pis.Length; i++) { mps.Add(new MappedParameter(pis[i], this.map.Parameters[i])); } this.parameters = mps.AsReadOnly(); } else { this.parameters = _emptyParameters; } }