private void CreateTypeBuilder() { TypeAttributes newAttributes = typeToIntercept.Attributes; newAttributes = FilterTypeAttributes(newAttributes); Type baseClass = GetGenericType(typeToIntercept); ModuleBuilder moduleBuilder = GetModuleBuilder(); typeBuilder = moduleBuilder.DefineType( "DynamicModule.ns.Wrapped_" + typeToIntercept.Name + "_" + Guid.NewGuid().ToString("N"), newAttributes, baseClass); this.mainTypeMapper = DefineGenericArguments(typeBuilder, baseClass); if (this.typeToIntercept.IsGenericType) { var definition = this.typeToIntercept.GetGenericTypeDefinition(); var mappedParameters = definition.GetGenericArguments().Select(t => this.mainTypeMapper.Map(t)).ToArray(); this.targetType = definition.MakeGenericType(mappedParameters); } else { this.targetType = this.typeToIntercept; } proxyInterceptionPipelineField = InterceptingProxyImplementor.ImplementIInterceptingProxy(typeBuilder); }
private void CreateTypeBuilder() { TypeAttributes newAttributes = TypeAttributes.Public | TypeAttributes.Class; ModuleBuilder moduleBuilder = GetModuleBuilder(); typeBuilder = moduleBuilder.DefineType(CreateTypeName(), newAttributes); DefineGenericArguments(); proxyInterceptionPipelineField = InterceptingProxyImplementor.ImplementIInterceptingProxy(typeBuilder); targetField = typeBuilder.DefineField("target", typeToIntercept, FieldAttributes.Private); typeToProxyField = typeBuilder.DefineField("typeToProxy", typeof(Type), FieldAttributes.Private); }
private void CreateTypeBuilder() { TypeAttributes newAttributes = typeToIntercept.Attributes; newAttributes = FilterTypeAttributes(newAttributes); Type baseClass = GetGenericType(typeToIntercept); ModuleBuilder moduleBuilder = GetModuleBuilder(); typeBuilder = moduleBuilder.DefineType( "DynamicModule.ns.Wrapped_" + typeToIntercept.Name + "_" + Guid.NewGuid().ToString("N"), newAttributes, baseClass); DefineGenericArguments(typeBuilder, baseClass); proxyInterceptionPipelineField = InterceptingProxyImplementor.ImplementIInterceptingProxy(typeBuilder); }