protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
		                                                      ProxyGenerationOptions options,
		                                                      OverrideMethodDelegate overrideMethod)
		{
			if (!method.Proxyable)
			{
				return new ForwardingMethodGenerator(method,
				                                     overrideMethod,
				                                     (c, m) => c.GetField("__target"));
			}

			var targetMethod = options.ProxyEffectiveType == null ? method.Method : InvocationHelper.GetMethodOnType(proxyTargetType, method.Method);

			if (targetMethod == null)
			{
				return new MinimialisticMethodGenerator(method, overrideMethod);
			}

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

			return new MethodWithInvocationGenerator(method,
			                                         @class.GetField("__interceptors"),
			                                         invocation,
			                                         (c, m) => c.GetField("__target").ToExpression(),
			                                         overrideMethod,
			                                         null);
		}
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
		                                                      ProxyGenerationOptions options,
		                                                      OverrideMethodDelegate overrideMethod)
		{
			if (methodsToSkip.Contains(method.Method))
				return null;

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

			if (ExplicitlyImplementedInterfaceMethod(method))
			{
#if SILVERLIGHT
				return null;
#else
				return ExplicitlyImplementedInterfaceMethodGenerator(method, @class, options, overrideMethod);
#endif
			}

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

			return new MethodWithInvocationGenerator(method,
			                                         @class.GetField("__interceptors"),
			                                         invocation,
			                                         (c, m) => new TypeTokenExpression(targetType),
			                                         overrideMethod,
			                                         null);
		}
        protected override MethodGenerator GetMethodGenerator(
            MetaMethod method,
            ClassEmitter @class,
            OverrideMethodDelegate overrideMethod
            )
        {
            if (!method.Proxyable)
            {
                return(new ForwardingMethodGenerator(
                           method,
                           overrideMethod,
                           (c, m) => c.GetField("__target")
                           ));
            }

            var invocation = GetInvocationType(method, @class);

            return(new MethodWithInvocationGenerator(
                       method,
                       @class.GetField("__interceptors"),
                       invocation,
                       (c, m) => c.GetField("__target"),
                       overrideMethod,
                       null
                       ));
        }
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
		                                                      ProxyGenerationOptions options,
		                                                      OverrideMethodDelegate overrideMethod)
		{
			if (methodsToSkip.Contains(method.Method))
			{
				return null;
			}

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

			if (IsDirectlyAccessible(method) == false)
			{
				return IndirectlyCalledMethodGenerator(method, @class, options, overrideMethod);
			}

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

			return new MethodWithInvocationGenerator(method,
			                                         @class.GetField("__interceptors"),
			                                         invocation,
			                                         (c, m) => c.GetField("__target").ToExpression(),
			                                         overrideMethod,
			                                         null);
		}
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                              ProxyGenerationOptions options,
                                                              OverrideMethodDelegate overrideMethod)
        {
            if (methodsToSkip.Contains(method.Method))
            {
                return(null);
            }

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

            if (ExplicitlyImplementedInterfaceMethod(method))
            {
                return(ExplicitlyImplementedInterfaceMethodGenerator(method, @class, options, overrideMethod));
            }

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

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     (c, m) => new TypeTokenExpression(targetType),
                                                     overrideMethod,
                                                     null));
        }
 public ForwardingMethodGenerator(
     MetaMethod method,
     OverrideMethodDelegate overrideMethod,
     GetTargetReferenceDelegate getTargetReference
     ) : base(method, overrideMethod)
 {
     this.getTargetReference = getTargetReference;
 }
		// 重载 InterfaceProxyWithTargetInterfaceContributor 中的方法,以指定使用扩展的 InvocationType 生成方法执行类
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod)
		{
			if (!method.Proxyable)
			{
				return new MinimialisticMethodGenerator(method, overrideMethod);
			}
			return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), this.GetInvocationType(method, @class, options), this.getTargetExpression, overrideMethod, null);
		}
		// 重载 InterfaceProxyWithTargetInterfaceContributor 中的方法,以指定使用扩展的 InvocationType 生成方法执行类
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod)
		{
			if (!method.Proxyable)
			{
				return new ForwardingMethodGenerator(method, overrideMethod, (c, m) => c.GetField("__target"));
			}
			return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), this.GetInvocationType(method, @class, options), (c, m) => c.GetField("__target").ToExpression(), overrideMethod, null);
		}
		public MethodWithInvocationGenerator(MetaMethod method, Reference interceptors, Type invocation, GetTargetExpressionDelegate getTargetExpression, OverrideMethodDelegate createMethod, IInvocationCreationContributor contributor)
			: base(method, createMethod)
		{
			this.invocation = invocation;
			this.getTargetExpression = getTargetExpression;
			this.interceptors = interceptors;
			this.contributor = contributor;
		}
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                              OverrideMethodDelegate overrideMethod)
        {
            if (!method.Proxyable)
            {
                return(new OptionallyForwardingMethodGenerator(method, overrideMethod, getTargetReference));
            }

            return(base.GetMethodGenerator(method, @class, overrideMethod));
        }
 public MethodWithInvocationGenerator(MetaMethod method, Reference interceptors, Type invocation,
                                      GetTargetExpressionDelegate getTargetExpression,
                                      OverrideMethodDelegate createMethod, IInvocationCreationContributor contributor)
     : base(method, createMethod)
 {
     this.invocation          = invocation;
     this.getTargetExpression = getTargetExpression;
     this.interceptors        = interceptors;
     this.contributor         = contributor;
 }
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                              ProxyGenerationOptions options,
                                                              OverrideMethodDelegate overrideMethod)
        {
            if (!method.Proxyable)
            {
                return new OptionallyForwardingMethodGenerator(method, overrideMethod, getTargetReference);
            }

            return base.GetMethodGenerator(method, @class, options, overrideMethod);
        }
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
		                                                      ProxyGenerationOptions options,
		                                                      OverrideMethodDelegate overrideMethod)
		{
			var invocation = GetInvocationType(method, @class, options);
			return new MethodWithInvocationGenerator(method,
			                                         @class.GetField("__interceptors"),
			                                         invocation,
			                                         (c, m) => c.GetField("__target").ToExpression(),
			                                         overrideMethod,
			                                         null);
		}
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                              ProxyGenerationOptions options,
                                                              OverrideMethodDelegate overrideMethod)
        {
            var invocation = GetInvocationType(method, @class, options);

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     (c, m) => c.GetField("__target").ToExpression(),
                                                     overrideMethod,
                                                     null));
        }
Exemple #15
0
        protected override MethodGenerator GetMethodGenerator(
            MetaMethod method,
            ClassEmitter @class,
            OverrideMethodDelegate overrideMethod
            )
        {
            if (method.Ignore)
            {
                return(null);
            }

            var methodIsDirectlyAccessible = IsDirectlyAccessible(method);

            if (!method.Proxyable)
            {
                if (methodIsDirectlyAccessible)
                {
                    return(new ForwardingMethodGenerator(
                               method,
                               overrideMethod,
                               (c, m) => c.GetField("__target")
                               ));
                }
                else
                {
                    return(IndirectlyCalledMethodGenerator(
                               method,
                               @class,
                               overrideMethod,
                               skipInterceptors: true
                               ));
                }
            }

            if (!methodIsDirectlyAccessible)
            {
                return(IndirectlyCalledMethodGenerator(method, @class, overrideMethod));
            }

            var invocation = GetInvocationType(method, @class);

            return(new MethodWithInvocationGenerator(
                       method,
                       @class.GetField("__interceptors"),
                       invocation,
                       (c, m) => c.GetField("__target"),
                       overrideMethod,
                       null
                       ));
        }
        private MethodGenerator ExplicitlyImplementedInterfaceMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                                              OverrideMethodDelegate overrideMethod)
        {
            var @delegate   = GetDelegateType(method, @class);
            var contributor = GetContributor(@delegate, method);
            var invocation  = new InheritanceInvocationTypeGenerator(targetType, method, null, contributor)
                              .Generate(@class, namingScope)
                              .BuildType();

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     (c, m) => new TypeTokenExpression(targetType),
                                                     overrideMethod,
                                                     contributor));
        }
 private void ImplementMethod(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options,
                              OverrideMethodDelegate overrideMethod)
 {
     {
         var generator = GetMethodGenerator(method, @class, options, overrideMethod);
         if (generator == null)
         {
             return;
         }
         var proxyMethod = generator.Generate(@class, options, namingScope);
         foreach (var attribute in method.Method.GetNonInheritableAttributes())
         {
             proxyMethod.DefineCustomAttribute(attribute);
         }
     }
 }
Exemple #18
0
        private MethodGenerator IndirectlyCalledMethodGenerator(MetaMethod method, ClassEmitter proxy,
                                                                OverrideMethodDelegate overrideMethod)
        {
            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,
                                                     proxy.GetField("__interceptors"),
                                                     invocation,
                                                     (c, m) => c.GetField("__target").ToExpression(),
                                                     overrideMethod,
                                                     contributor));
        }
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                              OverrideMethodDelegate overrideMethod)
        {
            if (!method.Proxyable)
            {
                return(new MinimialisticMethodGenerator(method, overrideMethod));
            }

            var invocation = GetInvocationType(method, @class);

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     getTargetExpression,
                                                     overrideMethod,
                                                     null));
        }
        protected override MethodGenerator GetMethodGenerator(
            MetaMethod method,
            ClassEmitter @class,
            ProxyGenerationOptions options,
            OverrideMethodDelegate overrideMethod)
        {
            if (templateMethod != null)
            {
                return(new TemplateMethodGenerator(method, overrideMethod, templateMethod));
            }

            if (registrar != null)
            {
                return(new TemplateMethodGenerator(method, overrideMethod, registrar.GetTemplate(method.Method)));
            }

            return(new TemplateMethodGenerator(method, overrideMethod));
        }
Exemple #21
0
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                              ProxyGenerationOptions options,
                                                              OverrideMethodDelegate overrideMethod)
        {
            if (!method.Proxyable)
            {
                return new ForwardingMethodGenerator(method,
                                                     overrideMethod,
                                                     (c, i) => fields[i.DeclaringType]);
            }

            var invocation = GetInvocationType(method, @class, options);
            return new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     getTargetExpression,
                                                     overrideMethod,
                                                     null);
        }
 public MethodWithInvocationGenerator(
     MetaMethod method,
     IExpression interceptors,
     Type invocation,
     GetTargetExpressionDelegate getTargetExpression,
     OverrideMethodDelegate createMethod,
     IInvocationCreationContributor contributor
     )
     : this(
         method,
         interceptors,
         invocation,
         getTargetExpression,
         null,
         createMethod,
         contributor
         )
 {
 }
Exemple #23
0
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                              ProxyGenerationOptions options,
                                                              OverrideMethodDelegate overrideMethod)
        {
            if (!method.Proxyable)
            {
                return(new ForwardingMethodGenerator(method,
                                                     overrideMethod,
                                                     (c, i) => fields[i.DeclaringType]));
            }

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

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     getTargetExpression,
                                                     overrideMethod,
                                                     null));
        }
 public TemplateMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod)
     : this(method, overrideMethod, GetTemplateMethod(method.Method.ReflectedType))
 {
 }
Exemple #25
0
 protected MethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod)
 {
     this.method         = method;
     this.overrideMethod = overrideMethod;
 }
		private MethodGenerator ExplicitlyImplementedInterfaceMethodGenerator(MetaMethod method, ClassEmitter @class,
		                                                                      ProxyGenerationOptions options,
		                                                                      OverrideMethodDelegate overrideMethod)
		{
			var @delegate = GetDelegateType(method, @class, options);
			var contributor = GetContributor(@delegate, method);
			var invocation = new InheritanceInvocationTypeGenerator(targetType, method, null, contributor)
				.Generate(@class, options, namingScope)
				.BuildType();
			return new MethodWithInvocationGenerator(method,
			                                             @class.GetField("__interceptors"),
			                                             invocation,
			                                             (c, m) => new TypeTokenExpression(targetType),
			                                             overrideMethod,
			                                             contributor);
		}
 public TemplateMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod, Action actionAsTemplate)
     : this(method, overrideMethod, actionAsTemplate.Method)
 {
 }
 protected abstract MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
                                                       ProxyGenerationOptions options,
                                                       OverrideMethodDelegate overrideMethod);
 public TemplateMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod, MethodInfo templateMethod)
     : base(method, overrideMethod)
 {
     this.templateMethod = templateMethod;
 }
Exemple #30
0
 public MinimialisticMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod)
     : base(method, overrideMethod)
 {
 }
		public OptionallyForwardingMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod,
		                                           GetTargetReferenceDelegate getTargetReference)
			: base(method, overrideMethod)
		{
			this.getTargetReference = getTargetReference;
		}
		private void ImplementMethod(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options,
		                             OverrideMethodDelegate overrideMethod)
		{
			{
				var generator = GetMethodGenerator(method, @class, options, overrideMethod);
				if (generator == null)
				{
					return;
				}
				var proxyMethod = generator.Generate(@class, options, namingScope);
				foreach (var attribute in method.Method.GetNonInheritableAttributes())
				{
					proxyMethod.DefineCustomAttribute(attribute);
				}
			}
		}
		protected abstract MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
		                                                      ProxyGenerationOptions options,
		                                                      OverrideMethodDelegate overrideMethod);
		public MinimialisticMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod)
			: base(method, overrideMethod)
		{
		}
Exemple #35
0
        protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod)
        {
            if (methodsToSkip.Contains(method.Method))
            {
                return(null);
            }

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

            if (IsDirectlyAccessible(method) == false)
            {
                return(IndirectlyCalledMethodGenerator(method, @class, options, overrideMethod));
            }

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

            return(new MethodWithInvocationGenerator(method,
                                                     @class.GetField("__interceptors"),
                                                     invocation,
                                                     (c, m) => c.GetField("__target").ToExpression(),
                                                     overrideMethod,
                                                     null));
        }
		private MethodGenerator IndirectlyCalledMethodGenerator(MetaMethod method, ClassEmitter proxy,
		                                                        ProxyGenerationOptions options,
		                                                        OverrideMethodDelegate overrideMethod)
		{
			var @delegate = GetDelegateType(method, proxy, options);
			var contributor = GetContributor(@delegate, method);
			var invocation = new CompositionInvocationTypeGenerator(targetType, method, null, false, contributor)
				.Generate(proxy, options, namingScope)
				.BuildType();
			return new MethodWithInvocationGenerator(method,
			                                         proxy.GetField("__interceptors"),
			                                         invocation,
			                                         (c, m) => c.GetField("__target").ToExpression(),
			                                         overrideMethod,
			                                         contributor);
		}