public MethodWithInvocationGenerator(MetaMethod method, Reference interceptors, Type invocation, GetTargetExpressionDelegate getTargetExpression, CreateMethodDelegate createMethod)
			: base(method, createMethod)
		{
			this.interceptors = interceptors;
			this.getTargetExpression = getTargetExpression;
			this.invocation = invocation;
		}
        /// <summary>
        /// Gets an existing value for a key or creates a new one. The creation of a new instance is not guarded. This introduces a risk that the creation method is called multiple times for the same key at the same time. Only one of the created values is added. This algorithm is ideal for creation methods that are either not likely to be called multiple times at the same time or that have an unpredictable execution time and a low usage of local reosurces.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="createMethod">The creation method.</param>
        /// <returns>The value.</returns>
        public TValue GetNonBlocking(TKey key, CreateMethodDelegate <TKey, TValue> createMethod)
        {
            TValue local;
            TValue local2;

            if (this.TryGet(key, out local))
            {
                return(local);
            }
            if (createMethod(key, out local2))
            {
                IDisposable disposable = this.WriterLock();
                try
                {
                    if (!this.Instances.TryGetValue(key, out local))
                    {
                        local = local2;
                        this.DoAdd(key, local);
                    }
                    return(local);
                }
                finally
                {
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            return(default(TValue));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ExitGames.Threading.SynchronizedSingletoFactory`2"/> class.
 /// </summary>
 /// <param name="defaultCreateMethod">The default create method.</param>
 /// <param name="lockTimeout">The max timeout to wait to enter a critical section.</param>
 public SynchronizedSingletonFactory(CreateMethodDelegate <TKey, TValue> defaultCreateMethod, int lockTimeout)
 {
     this.syncObjects          = new Dictionary <TKey, object>();
     this.lockTimeout          = lockTimeout;
     this.readerWriterLockSlim = new ReaderWriterLockSlim();
     this.defaultCreateMethod  = defaultCreateMethod;
     this.instances            = new Dictionary <TKey, TValue>();
 }
        /// <summary>
        /// Gets an existing value for a key or creates a new one. The creation of a new instance is guarded with a sync root that is unique per key. This algorithm is ideal for creation methods that do not return fast.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="createMethod">The creation method.</param>
        /// <returns>The value.</returns>
        public TValue GetBlockingInstance(TKey key, CreateMethodDelegate <TKey, TValue> createMethod)
        {
            TValue local;

            if (!this.TryGet(key, out local))
            {
                object      obj2;
                bool        flag;
                IDisposable disposable = Lock.TryEnter(this.syncObjects, this.lockTimeout);
                try
                {
                    if (!this.syncObjects.TryGetValue(key, out obj2))
                    {
                        obj2 = new object();
                        this.syncObjects.Add(key, obj2);
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }
                finally
                {
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                if (flag)
                {
                    try
                    {
                        this.GetBlockingInstance(key, createMethod, obj2, out local);
                        return(local);
                    }
                    finally
                    {
                        IDisposable disposable2 = Lock.TryEnter(this.syncObjects, this.lockTimeout);
                        try
                        {
                            this.syncObjects.Remove(key);
                        }
                        finally
                        {
                            if (disposable2 != null)
                            {
                                disposable2.Dispose();
                            }
                        }
                    }
                }
                this.GetBlockingInstance(key, createMethod, obj2, out local);
            }
            return(local);
        }
        public TValue GetNonBlocking(TKey key, CreateMethodDelegate <TKey, TValue> createMethod)
        {
            CacheKey <TKey, TValue> key2;

            if (!this.CacheTryGet(key, out key2))
            {
                key2 = this.GetCacheKey(key, createMethod);
            }
            return(base.GetNonBlocking(key2).Value);
        }
 protected SynchronizedCachedSingletonFactory(CreateMethodDelegate <TKey, TValue> defaultCreateMethod, Action <TKey, TValue> removeCallback, TimeSpan cacheTimeSpan, int lockTimeout)
     : base(null, lockTimeout)
 {
     this.cacheKeys            = new Dictionary <TKey, CacheKey <TKey, TValue> >();
     this.readerWriterLockSlim = new ReaderWriterLockSlim();
     this.cache          = new Cache();
     this.name           = Guid.NewGuid().ToString("D") + ".";
     this.CacheTimeOut   = cacheTimeSpan;
     this.DoCreateMethod = defaultCreateMethod;
     base.CreateMethod   = new CreateMethodDelegate <CacheKey <TKey, TValue>, CacheValue <TKey, TValue> >(this.Create);
     this.RemoveCallback = removeCallback;
 }
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, CreateMethodDelegate createMethod)
		{
			if (!method.Proxyable)
			{
				return new MinimialisticMethodGenerator(method,
														createMethod);
			}

			var invocation = GetInvocationType(method, @class, options);
			return new MethodWithInvocationGenerator(method,
													 @class.GetField("__interceptors"),
													 invocation,
													 getTargetExpression,
													 createMethod);
		}
 private void ImplementMethod(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options,
                              CreateMethodDelegate createMethod)
 {
     {
         var generator = GetMethodGenerator(method, @class, options, createMethod);
         if (generator == null)
         {
             return;
         }
         var proxyMethod = generator.Generate(@class, options, namingScope);
         foreach (var attribute in AttributeUtil.GetNonInheritableAttributes(method.Method))
         {
             proxyMethod.DefineCustomAttribute(attribute);
         }
     }
 }
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, CreateMethodDelegate createMethod)
		{
			if (!method.Proxyable)
			{
				return new ForwardingMethodGenerator(method,
				                                     createMethod,
				                                     (c, m) => c.GetField("__target"));
			}

			var invocation = GetInvocationType(method, @class, options);

			return new MethodWithInvocationGenerator(method,
			                                         @class.GetField("__interceptors"),
			                                         invocation,
			                                         (c, m) => c.GetField("__target").ToExpression(),
			                                         createMethod);
		}
        /// <summary>
        /// Gets an existing value for a key or creates a new one with the default <see cref="P:ExitGames.Threading.UnsynchronizedSingletonFactory`2.CreateMethod"/>.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="createMethod">
        /// The method that creates a new value if the key has not been added yet.
        /// </param>
        /// <returns>
        /// The value for the key.
        /// </returns>
        public virtual TValue Get(TKey key, CreateMethodDelegate <TKey, TValue> createMethod)
        {
            TValue local;
            TValue local2;

            if (this.TryGet(key, out local))
            {
                return(local);
            }
            if (createMethod(key, out local2))
            {
                local = local2;
                this.DoAdd(key, local);
                return(local);
            }
            return(default(TValue));
        }
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, CreateMethodDelegate createMethod)
		{
			if (methodsToSkip.Contains(method.Method)) return null;

			if (!method.Proxyable)
			{
				return new MinimialisticMethodGenerator(method,
				                                        createMethod);
			}

			var invocation = GetInvocationType(method, @class, options);

			return new MethodWithInvocationGenerator(method,
			                                         @class.GetField("__interceptors"),
			                                         invocation,
			                                         (c, m) => new TypeTokenExpression(targetType),
			                                         createMethod);
		}
        /// <summary>
        /// Helper method of <see cref="M:ExitGames.Threading.SynchronizedSingletonFactory`2.GetBlockingInstance(`0,ExitGames.Threading.CreateMethodDelegate{`0,`1})">GetBlockingInstance</see> that creates the instance.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="createMethod">The creation method method. </param>
        /// <param name="syncObject">The sync object for the key.</param>
        /// <param name="result">The result value.</param>
        private void GetBlockingInstance(TKey key, CreateMethodDelegate <TKey, TValue> createMethod, object syncObject, out TValue result)
        {
            IDisposable disposable = Lock.TryEnter(syncObject, this.lockTimeout);

            try
            {
                if (!this.TryGet(key, out result) && createMethod(key, out result))
                {
                    IDisposable disposable2 = this.WriterLock();
                    try
                    {
                        TValue local;
                        if (!this.Instances.TryGetValue(key, out local))
                        {
                            this.DoAdd(key, result);
                        }
                        else
                        {
                            result = local;
                        }
                    }
                    finally
                    {
                        if (disposable2 != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Exemple #13
0
 public CacheKey(string cacheKey, TKey key, CreateMethodDelegate <TKey, TValue> createMethod)
 {
     this.Key          = key;
     this.AspCacheKey  = cacheKey;
     this.CreateMethod = createMethod;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ExitGames.Threading.UnsynchronizedSingletonFactory`2"/> class.
 /// </summary>
 /// <param name="defaultCreateMethod">
 /// The default function that creates new instances.
 /// </param>
 public UnsynchronizedSingletonFactory(CreateMethodDelegate <TKey, TValue> defaultCreateMethod)
 {
     this.defaultCreateMethod = defaultCreateMethod;
     this.instances           = new Dictionary <TKey, TValue>();
 }
 public MethodWithInvocationGenerator(MetaMethod method, Reference interceptors, Type invocation, GetTargetExpressionDelegate getTargetExpression, CreateMethodDelegate createMethod)
     : base(method, createMethod)
 {
     this.interceptors        = interceptors;
     this.getTargetExpression = getTargetExpression;
     this.invocation          = invocation;
 }
Exemple #16
0
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, CreateMethodDelegate createMethod)
        {
            if (methodsToSkip.Contains(method.Method))
            {
                return(null);
            }

            if (!method.Proxyable)
            {
                return(new MinimialisticMethodGenerator(method,
                                                        createMethod));
            }

            var invocation = GetInvocationType(method, @class, options);

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     (c, m) => new TypeTokenExpression(targetType),
                                                     createMethod));
        }
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, CreateMethodDelegate createMethod)
        {
            if (!method.Proxyable)
            {
                return(new MinimialisticMethodGenerator(method,
                                                        createMethod));
            }

            var invocation = GetInvocationType(method, @class, options);

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     getTargetExpression,
                                                     createMethod));
        }
		protected abstract MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
		                                           ProxyGenerationOptions options, CreateMethodDelegate createMethod);
		private void ImplementMethod(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options,
		                                        CreateMethodDelegate createMethod)
		{
			{
				var generator = GetMethodGenerator(method, @class, options, createMethod);
				if (generator == null) return;
				var proxyMethod = generator.Generate(@class, options, namingScope);
				foreach (var attribute in AttributeUtil.GetNonInheritableAttributes(method.Method))
				{
					proxyMethod.DefineCustomAttribute(attribute);
				}
			}
		}
Exemple #20
0
 public ForwardingMethodGenerator(MetaMethod method, CreateMethodDelegate createMethod, GetTargetReferenceDelegate getTargetReference)
     : base(method, createMethod)
 {
     this.getTargetReference = getTargetReference;
 }
        static System.Type GenerateFunctionType(System.Type functionType)
        {
            SQLiteFunctionAttribute attribute = AttributeExtensions.GetCustomAttribute <SQLiteFunctionAttribute>(functionType);

            if (attribute == null)
            {
                return(null);
            }
            bool        ex       = TypeExtensions.IsInheritFrom(functionType, typeof(SQLiteFunctionEx)) || attribute.Type == FunctionTypes.Collation;
            FastWrapper baseType = GetType(ex ? "System.Data.SQLite.SQLiteFunctionEx" : "System.Data.SQLite.SQLiteFunction");


            System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName(functionType.Namespace + ".DynamicClass_" + functionType.Name);
            System.Reflection.Emit.AssemblyBuilderAccess accemblyBuilderAccess =
#if netcore
                System.Reflection.Emit.AssemblyBuilderAccess.Run;
#else
                IsDebug
                    ? System.Reflection.Emit.AssemblyBuilderAccess.RunAndSave
                    : System.Reflection.Emit.AssemblyBuilderAccess.Run;
#endif
            System.Reflection.Emit.AssemblyBuilder assembly =
#if netcore
                System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly(assemblyName, accemblyBuilderAccess);
#else
                System.AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, accemblyBuilderAccess);
#endif
#if !netcore
            bool canSave = (accemblyBuilderAccess == System.Reflection.Emit.AssemblyBuilderAccess.RunAndSave || accemblyBuilderAccess == System.Reflection.Emit.AssemblyBuilderAccess.Save);
#endif
            System.Reflection.Emit.ModuleBuilder module =
#if netcore
                assembly.DefineDynamicModule(assemblyName.Name);
#else
                canSave
                    ? assembly.DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".dll")
                    : assembly.DefineDynamicModule(assemblyName.Name);//, n.Name + ".dll");
#endif
            System.Reflection.Emit.TypeBuilder type = module.DefineType(
                assemblyName.Name + ".DynamicClass",
                System.Reflection.TypeAttributes.Public | System.Reflection.TypeAttributes.Sealed | System.Reflection.TypeAttributes.AutoClass,
                baseType.Type,
                System.Type.EmptyTypes);

            {
                FastWrapper wrapper = GetType("System.Data.SQLite.SQLiteFunctionAttribute");
                System.Reflection.PropertyInfo[] properties = new System.Reflection.PropertyInfo[] {
                    wrapper.Type.GetProperty("Name"),
                    wrapper.Type.GetProperty("Arguments"),
                    wrapper.Type.GetProperty("FuncType"),
                };
                System.Reflection.Emit.CustomAttributeBuilder attributeBuilder = new System.Reflection.Emit.CustomAttributeBuilder(wrapper.Type.GetConstructor(System.Type.EmptyTypes), new object[0],
                                                                                                                                   properties, new object[] {
                    attribute.Name,
                    attribute.Arguments,
                    TypeExtensions.Convert(attribute.Type, GetType("System.Data.SQLite.FunctionType").Type),
                });
                type.SetCustomAttribute(attributeBuilder);
            }
            System.Reflection.Emit.FieldBuilder _o = type.DefineField("_o", functionType, FieldAttributes.Private);

            {
                System.Reflection.Emit.ConstructorBuilder ctor = type.DefineConstructor(
                    System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.HideBySig | System.Reflection.MethodAttributes.SpecialName | System.Reflection.MethodAttributes.RTSpecialName,
                    System.Reflection.CallingConventions.HasThis,
                    System.Type.EmptyTypes);
                System.Reflection.Emit.ILGenerator il = ctor.GetILGenerator();
                il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
                il.Emit(System.Reflection.Emit.OpCodes.Call, baseType.Type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance | BindingFlags.Instance, null, System.Type.EmptyTypes, new System.Reflection.ParameterModifier[0]));
                il.Emit(System.Reflection.Emit.OpCodes.Nop);
                il.Emit(System.Reflection.Emit.OpCodes.Nop);
                il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
                il.Emit(System.Reflection.Emit.OpCodes.Newobj, functionType.GetConstructor(System.Type.EmptyTypes));
                il.Emit(System.Reflection.Emit.OpCodes.Stfld, _o);
                il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
                il.Emit(System.Reflection.Emit.OpCodes.Ldfld, _o);
                il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
                if (attribute.Type == FunctionTypes.Collation)
                {
                    il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_1);
                }
                else
                {
                    il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0);
                }
                il.Emit(System.Reflection.Emit.OpCodes.Callvirt, functionType.GetMethod("Init", BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, new System.Type[] {
                    typeof(object), typeof(bool)
                }, null));
                il.Emit(System.Reflection.Emit.OpCodes.Nop);
                il.Emit(System.Reflection.Emit.OpCodes.Ret);
            }
            CreateMethodDelegate createMethod = (methodInfo, action) => {
                System.Reflection.ParameterInfo[] parameters = methodInfo.GetParameters();
                System.Type[] parameterTypes = new System.Type[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                {
                    parameterTypes[i] = parameters[i].ParameterType;
                }
                System.Reflection.Emit.MethodBuilder method = type.DefineMethod(methodInfo.Name, (methodInfo.Attributes | MethodAttributes.NewSlot) ^ MethodAttributes.NewSlot, methodInfo.CallingConvention, methodInfo.ReturnType, parameterTypes);
                for (int i = 0; i < parameters.Length; i++)
                {
                    System.Reflection.Emit.ParameterBuilder parameter = method.DefineParameter(i + 1, parameters[i].Attributes, parameters[i].Name);
                    if (parameters[i].IsOptional)
                    {
                        if (parameters[i].ParameterType.IsValueType && parameters[i].DefaultValue == null)
                        {
                            continue;
                        }
                        parameter.SetConstant(parameters[i].DefaultValue);
                    }
                }
                System.Reflection.Emit.ILGenerator il = method.GetILGenerator();
                bool hasReturn = (methodInfo.ReturnType != typeof(void));
                System.Reflection.Emit.LocalBuilder @return = null;
                if (hasReturn)
                {
                    @return = il.DeclareLocal(methodInfo.ReturnType);
                }
                il.Emit(System.Reflection.Emit.OpCodes.Nop);
                il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
                il.Emit(System.Reflection.Emit.OpCodes.Ldfld, _o);
                action(functionType.GetMethod(methodInfo.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance), method, il);
                il.Emit(System.Reflection.Emit.OpCodes.Ret);
            };
            if (attribute.Type == FunctionTypes.Scalar)
            {
                createMethod(baseType.Type.GetMethod("Invoke"), (methodInfo, method, il) => {
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
                    il.Emit(System.Reflection.Emit.OpCodes.Callvirt, methodInfo);
                    il.Emit(System.Reflection.Emit.OpCodes.Stloc_0);
                    System.Reflection.Emit.Label label = il.DefineLabel();
                    il.Emit(System.Reflection.Emit.OpCodes.Br_S, label);
                    il.MarkLabel(label);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldloc_0);
                });
            }
            else if (attribute.Type == FunctionTypes.Collation)
            {
                createMethod(baseType.Type.GetMethod("Compare"), (methodInfo, method, il) => {
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_2);
                    il.Emit(System.Reflection.Emit.OpCodes.Callvirt, methodInfo);
                    il.Emit(System.Reflection.Emit.OpCodes.Stloc_0);
                    System.Reflection.Emit.Label label = il.DefineLabel();
                    il.Emit(System.Reflection.Emit.OpCodes.Br_S, label);
                    il.MarkLabel(label);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldloc_0);
                });
            }
            else
            {
                createMethod(baseType.Type.GetMethod("Final"), (methodInfo, method, il) => {
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
                    il.Emit(System.Reflection.Emit.OpCodes.Callvirt, methodInfo);
                    il.Emit(System.Reflection.Emit.OpCodes.Stloc_0);
                    System.Reflection.Emit.Label label = il.DefineLabel();
                    il.Emit(System.Reflection.Emit.OpCodes.Br_S, label);
                    il.MarkLabel(label);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldloc_0);
                });
                createMethod(baseType.Type.GetMethod("Step"), (methodInfo, method, il) => {
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_2);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3);
                    il.Emit(System.Reflection.Emit.OpCodes.Callvirt, methodInfo);
                    il.Emit(System.Reflection.Emit.OpCodes.Nop);
                });
            }
            {
                System.Reflection.MethodInfo methodInfo_base = baseType.Type.GetMethod("Dispose", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, new System.Type[] { typeof(bool) }, null);
                createMethod(methodInfo_base, (methodInfo, method, il) => {
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
                    il.Emit(System.Reflection.Emit.OpCodes.Callvirt, methodInfo);
                    il.Emit(System.Reflection.Emit.OpCodes.Nop);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
                    il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
                    il.Emit(System.Reflection.Emit.OpCodes.Call, methodInfo_base);
                    il.Emit(System.Reflection.Emit.OpCodes.Nop);
                });
            }

#if netcore20
            var result = type.CreateTypeInfo();
#else
            var result = type.CreateType();
#endif
#if !netcore
            if (canSave)
            {
                assembly.Save(assemblyName.Name + ".dll");
            }
#endif
            return(result);
        }
Exemple #22
0
 public MinimialisticMethodGenerator(MetaMethod method, CreateMethodDelegate createMethod)
     : base(method, createMethod)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ExitGames.Threading.CachedSingletonFactory.CachedSingletonFactoryAbsolute`2 " > class.
 /// </summary>
 /// <param name="defaultCreateMethod">The default create method.</param>
 /// <param name="removeCallback">The remove callback.</param>
 /// <param name="cacheTimeSpan">The cache time span.</param>
 /// <param name="lockTimeout">The lock timeout in ms.</param>
 public CachedSingletonFactoryAbsolute(CreateMethodDelegate <TKey, TValue> defaultCreateMethod, Action <TKey, TValue> removeCallback, TimeSpan cacheTimeSpan, int lockTimeout)
     : base(defaultCreateMethod, removeCallback, cacheTimeSpan, lockTimeout)
 {
 }
 public virtual TValue Get(TKey key, CreateMethodDelegate <TKey, TValue> createMethod)
 {
     return(this.GetBlockingInstance(key, createMethod));
 }
Exemple #25
0
 protected MethodGenerator(MetaMethod method, CreateMethodDelegate createMethod)
 {
     this.method       = method;
     this.createMethod = createMethod;
 }
        // Methods
        private CacheKey <TKey, TValue> GetCacheKey(TKey local1, CreateMethodDelegate <TKey, TValue> delegate1)
        {
            Guid guid = Guid.NewGuid();

            return(new CacheKey <TKey, TValue>(this.name + guid.ToString("D"), local1, delegate1));
        }
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, CreateMethodDelegate createMethod)
        {
            if (!method.Proxyable)
            {
                return(new ForwardingMethodGenerator(method,
                                                     createMethod,
                                                     (c, m) => c.GetField("__target")));
            }

            var invocation = GetInvocationType(method, @class, options);

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     (c, m) => c.GetField("__target").ToExpression(),
                                                     createMethod));
        }
 protected abstract MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                       ProxyGenerationOptions options, CreateMethodDelegate createMethod);
		public ForwardingMethodGenerator(MetaMethod method, CreateMethodDelegate createMethod, GetTargetReferenceDelegate getTargetReference)
			: base(method, createMethod)
		{
			this.getTargetReference = getTargetReference;
		}