Esempio n. 1
0
        private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options)
        {
            var scope = emitter.ModuleScope;
            var key   = new CacheKey(method.Method, CompositionInvocationTypeGenerator.BaseType, null, null);

            // no locking required as we're already within a lock
            var invocation = scope.GetFromCache(key);

            if (invocation != null)
            {
                return(invocation);
            }

            invocation = new CompositionInvocationTypeGenerator(method.Method.DeclaringType,
                                                                method,
                                                                method.Method,
                                                                false,
                                                                null)
                         .Generate(emitter, options, namingScope)
                         .BuildType();

            scope.RegisterInCache(key, invocation);

            return(invocation);
        }
Esempio n. 2
0
        private MethodGenerator IndirectlyCalledMethodGenerator(
            MetaMethod method,
            ClassEmitter proxy,
            OverrideMethodDelegate overrideMethod,
            bool skipInterceptors = false
            )
        {
            var @delegate   = GetDelegateType(method, proxy);
            var contributor = GetContributor(@delegate, method);
            var invocation  = new CompositionInvocationTypeGenerator(
                targetType,
                method,
                null,
                false,
                contributor
                )
                              .Generate(proxy, namingScope)
                              .BuildType();

            return(new MethodWithInvocationGenerator(
                       method,
                       skipInterceptors ? NullExpression.Instance : proxy.GetField("__interceptors"),
                       invocation,
                       (c, m) => c.GetField("__target"),
                       overrideMethod,
                       contributor
                       ));
        }
        private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options)
        {
            var scope = @class.ModuleScope;

            Type[] invocationInterfaces;
            if (canChangeTarget)
            {
                invocationInterfaces = new[] { typeof(IInvocation), typeof(IChangeProxyTarget) };
            }
            else
            {
                invocationInterfaces = new[] { typeof(IInvocation) };
            }

            var key = new CacheKey(method.Method, CompositionInvocationTypeGenerator.BaseType, invocationInterfaces, null);

            // no locking required as we're already within a lock

            var invocation = scope.GetFromCache(key);

            if (invocation != null)
            {
                return(invocation);
            }

            invocation = new CompositionInvocationTypeGenerator(method.Method.DeclaringType,
                                                                method,
                                                                method.Method,
                                                                canChangeTarget,
                                                                null)
                         .Generate(@class, options, namingScope).BuildType();

            scope.RegisterInCache(key, invocation);

            return(invocation);
        }