Skip to content
Permalink
Browse files

[Build] NETStandard: Switch from AssemblyBuilder.DefineDynamicAssembly

  • Loading branch information
xen2 committed Aug 2, 2019
1 parent 382953c commit c291dac0ac88fa3d7493599fa312fa3c6ed5680b
@@ -38,15 +38,15 @@ public static object CreateConcreteInstance([NotNull] Type baseType)
var asmName = new AssemblyName($"ConcreteObject_{Guid.NewGuid():N}");

// Create assembly (in memory)
var asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
var asmBuilder = AssemblyBuilder.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
var moduleBuilder = asmBuilder.DefineDynamicModule("DynamicModule");

// Define type
var typeBuilder = moduleBuilder.DefineType($"{baseType}Impl");
InitializeTypeBuilderFromType(typeBuilder, baseType);

// Create type
constructedType = typeBuilder.CreateType();
constructedType = typeBuilder.CreateTypeInfo();
ConstructedTypes.Add(baseType, constructedType);

}
@@ -17,6 +17,7 @@
<PackageReference Include="Microsoft.Build" Version="16.0.461" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.2" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" ExcludeAssets="runtime" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.7.0" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
@@ -39,7 +39,7 @@ public static IUnloadable CreateUnloadableObject(Type baseType, string typeName,
var asmName = new AssemblyName($"YamlProxy_{Guid.NewGuid():N}");

// Create assembly (in memory)
var asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
var asmBuilder = AssemblyBuilder.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
var moduleBuilder = asmBuilder.DefineDynamicModule("DynamicModule");

// Create type
@@ -107,7 +107,7 @@ public static IUnloadable CreateUnloadableObject(Type baseType, string typeName,
// User-registered callbacks
ProcessProxyType?.Invoke(baseType, typeBuilder);

proxyType = typeBuilder.CreateType();
proxyType = typeBuilder.CreateTypeInfo();
proxyTypes.Add(baseType, proxyType);
}
}

0 comments on commit c291dac

Please sign in to comment.
You can’t perform that action at this time.