private async Task <Type> CompileResultTypeAsync(DynamicDtoTypeBuildingContext context) { var proxyClassName = GetProxyTypeName(context.ModelType, "Proxy"); var tb = GetTypeBuilder(context.ModelType, proxyClassName, new List <Type> { typeof(IDynamicDtoProxy) }); var constructor = tb.DefineDefaultConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName); using (context.OpenNamePrefix(proxyClassName)) { var properties = await GetDynamicPropertiesAsync(context.ModelType, context); foreach (var property in properties) { if (context.PropertyFilter == null || context.PropertyFilter.Invoke(property.PropertyName)) { CreateProperty(tb, property.PropertyName, property.PropertyType); } } var objectType = tb.CreateType(); context.ClassCreated(objectType); return(objectType); } }
private async Task <Type> BuildNestedTypeAsync(EntityPropertyDto propertyDto, DynamicDtoTypeBuildingContext context) { if (propertyDto.DataType != DataTypes.Object) { throw new NotSupportedException($"{nameof(BuildNestedTypeAsync)}: unsupported type of property (expected '{DataTypes.Object}', actual: '{propertyDto.DataType}')"); } // todo: build name of the class according ot the level of the property using (context.OpenNamePrefix(propertyDto.Name)) { var className = context.CurrentPrefix.Replace('.', '_'); var tb = GetTypeBuilder(typeof(object), className, new List <Type> { typeof(IDynamicNestedObject) }); var constructor = tb.DefineDefaultConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName); foreach (var property in propertyDto.Properties) { //if (propertyFilter == null || propertyFilter.Invoke(property.PropertyName)) var propertyType = await GetDtoPropertyTypeAsync(property, context); CreateProperty(tb, property.Name, propertyType); } var objectType = tb.CreateType(); context.ClassCreated(objectType); return(objectType); } }
private async Task <Type> CompileResultTypeAsync(Type baseType, string proxyClassName, List <Type> interfaces, List <DynamicProperty> properties, DynamicDtoTypeBuildingContext context) { var tb = GetTypeBuilder(baseType, proxyClassName, interfaces.Union(new List <Type> { typeof(IDynamicDtoProxy) })); var constructor = tb.DefineDefaultConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName); foreach (var property in properties) { CreateProperty(tb, property.PropertyName, property.PropertyType); } var objectType = tb.CreateType(); context.ClassCreated(objectType); return(objectType); }