Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into v5.x
  • Loading branch information
ENikS committed Feb 6, 2019
2 parents 5a6f11b + 595fc62 commit 1e0be91
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 42 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void CreateTypeBuilder()
{
TypeAttributes newAttributes = TypeAttributes.Public | TypeAttributes.Class;

ModuleBuilder moduleBuilder = GetModuleBuilder();
ModuleBuilder moduleBuilder = InterceptorClassGenerator.CreateModuleBuilder(AssemblyBuilder);
_typeBuilder = moduleBuilder.DefineType(CreateTypeName(), newAttributes);

_mainInterfaceMapper = DefineGenericArguments();
Expand Down
25 changes: 25 additions & 0 deletions src/Interceptors/InterceptorClassGenerator.Desktop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Concurrent;
using System.Reflection.Emit;

namespace Unity.Interception.Interceptors
{
public static class InterceptorClassGenerator
{
private static readonly ConcurrentDictionary<AssemblyBuilder, ModuleBuilder> ModuleByAssembly =
new ConcurrentDictionary<AssemblyBuilder, ModuleBuilder>();

public static ModuleBuilder CreateModuleBuilder(AssemblyBuilder assemblyBuilder)
{
return ModuleByAssembly.GetOrAdd(assemblyBuilder, assembly =>
{
string moduleName = Guid.NewGuid().ToString("N");
#if DEBUG_SAVE_GENERATED_ASSEMBLY
return AssemblyBuilder.DefineDynamicModule(moduleName, moduleName + ".dll", true);
#else
return assembly.DefineDynamicModule(moduleName);
#endif
});
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void CreateTypeBuilder()

Type baseClass = GetGenericType(_typeToIntercept);

ModuleBuilder moduleBuilder = InterceptingClassGenerator.GetModuleBuilder();
ModuleBuilder moduleBuilder = InterceptorClassGenerator.CreateModuleBuilder(AssemblyBuilder);
_typeBuilder = moduleBuilder.DefineType(
"DynamicModule.ns.Wrapped_" + _typeToIntercept.Name + "_" + Guid.NewGuid().ToString("N"),
newAttributes,
Expand Down

0 comments on commit 1e0be91

Please sign in to comment.