Merge pull request #25 from yfital/interception_works_once
Fix multiple intreceptors issue due to .net core logic change
This commit is contained in:
Коммит
595fc621f4
|
@ -1,20 +0,0 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.Reflection.Emit;
|
||||
|
||||
namespace Unity.Interception.Interceptors.InstanceInterceptors.InterfaceInterception
|
||||
{
|
||||
public partial class InterfaceInterceptorClassGenerator
|
||||
{
|
||||
private static ModuleBuilder GetModuleBuilder()
|
||||
{
|
||||
string moduleName = Guid.NewGuid().ToString("N");
|
||||
#if DEBUG_SAVE_GENERATED_ASSEMBLY
|
||||
return AssemblyBuilder.DefineDynamicModule(moduleName, moduleName + ".dll", true);
|
||||
#else
|
||||
return AssemblyBuilder.DefineDynamicModule(moduleName);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -176,7 +176,7 @@ namespace Unity.Interception.Interceptors.InstanceInterceptors.InterfaceIntercep
|
|||
{
|
||||
TypeAttributes newAttributes = TypeAttributes.Public | TypeAttributes.Class;
|
||||
|
||||
ModuleBuilder moduleBuilder = GetModuleBuilder();
|
||||
ModuleBuilder moduleBuilder = InterceptorClassGenerator.CreateModuleBuilder(AssemblyBuilder);
|
||||
_typeBuilder = moduleBuilder.DefineType(CreateTypeName(), newAttributes);
|
||||
|
||||
_mainInterfaceMapper = DefineGenericArguments();
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.Reflection.Emit;
|
||||
|
||||
namespace Unity.Interception.Interceptors.TypeInterceptors.VirtualMethodInterception.InterceptingClassGeneration
|
||||
{
|
||||
public partial class InterceptingClassGenerator
|
||||
{
|
||||
private static ModuleBuilder GetModuleBuilder()
|
||||
{
|
||||
string moduleName = Guid.NewGuid().ToString("N");
|
||||
#if DEBUG_SAVE_GENERATED_ASSEMBLY
|
||||
return AssemblyBuilder.DefineDynamicModule(moduleName, moduleName + ".dll", true);
|
||||
#else
|
||||
return AssemblyBuilder.DefineDynamicModule(moduleName);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -214,7 +214,7 @@ namespace Unity.Interception.Interceptors.TypeInterceptors.VirtualMethodIntercep
|
|||
|
||||
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,
|
||||
|
|
Загрузка…
Ссылка в новой задаче