private static void Init() { if (DynamicWrapper._moduleBuilder == null) { lock (DynamicWrapper._lock) { if (DynamicWrapper._moduleBuilder == null) { AssemblyName assemblyName = new AssemblyName("Newtonsoft.Json.Dynamic"); assemblyName.KeyPair = new StrongNameKeyPair(DynamicWrapper.GetStrongKey()); AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); DynamicWrapper._moduleBuilder = assemblyBuilder.DefineDynamicModule("Newtonsoft.Json.DynamicModule", false); } } } }
public static Type GetWrapper(Type interfaceType, Type realObjectType) { Type type = DynamicWrapper._wrapperDictionary.GetType(interfaceType, realObjectType); if (type == null) { lock (DynamicWrapper._lock) { type = DynamicWrapper._wrapperDictionary.GetType(interfaceType, realObjectType); if (type == null) { type = DynamicWrapper.GenerateWrapperType(interfaceType, realObjectType); DynamicWrapper._wrapperDictionary.SetType(interfaceType, realObjectType, type); } } } return(type); }
private static void Init() { if (DynamicWrapper._moduleBuilder != null) { return; } lock (DynamicWrapper._lock) { if (DynamicWrapper._moduleBuilder != null) { return; } DynamicWrapper._moduleBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Newtonsoft.Json.Dynamic") { KeyPair = new StrongNameKeyPair(DynamicWrapper.GetStrongKey()) }, AssemblyBuilderAccess.Run).DefineDynamicModule("Newtonsoft.Json.DynamicModule", false); } }
public static T CreateWrapper <T>(object realObject) where T : class { DynamicWrapperBase dynamicWrapperBase = (DynamicWrapperBase)Activator.CreateInstance(DynamicWrapper.GetWrapper(typeof(T), realObject.GetType())); dynamicWrapperBase.UnderlyingObject = realObject; return(dynamicWrapperBase as T); }