예제 #1
0
 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);
             }
         }
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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);
        }