private static void GetDynamicTypeNameInternal(Type type, StringBuilder builder) { builder.Append(CSharpWriter.CleanGenericName(type.Name)); if (type.IsGenericType) { builder.Append("_"); foreach (var t in type.GetGenericArguments()) { GetDynamicTypeNameInternal(t, builder); } } }
private ProxyBuilder(ModuleBuilder moduleBuilder, Type delegateType, bool @return) { var cleanTypeName = CSharpWriter.CleanGenericName(delegateType.Name); var suffix = string.Empty; if (delegateType.IsGenericType) { suffix = "`" + delegateType.GetGenericArguments().Length; } typeBuilder = moduleBuilder.DefineType( $"{cleanTypeName}Proxy{suffix}", //name TypeAttributes.Public | //attributes TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit ); this.delegateType = delegateType; if (delegateType.IsGenericType) { var argNames = delegateType.GetGenericTypeDefinition().GetGenericArguments().Select(a => a.Name).ToArray(); genericArguments = typeBuilder.DefineGenericParameters(argNames); } else { genericArguments = Type.EmptyTypes; } GenerateFields(); GenerateInvoke(@return); GenerateLambda(); GenerateConstructor(); }