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); }
public InvocationWithGenericDelegateContributor(Type delegateType, MetaMethod method, Reference targetReference) { Debug.Assert(delegateType.GetTypeInfo().IsGenericType, "delegateType.IsGenericType"); this.delegateType = delegateType; this.method = method; this.targetReference = targetReference; }
public static void Clear() { cachedType = null; cachedClass = null; cachedVariable = null; cachedMethod = 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); }
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; }
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); }
public MethodWithInvocationGenerator(MetaMethod method, Reference interceptors, Type invocation, GetTargetExpressionDelegate getTargetExpression, CreateMethodDelegate createMethod) : base(method, createMethod) { this.interceptors = interceptors; this.getTargetExpression = getTargetExpression; this.invocation = invocation; }
// 重载 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; }
public InvocationWithDelegateContributor(Type delegateType, Type targetType,MetaMethod method, INamingScope namingScope) { Debug.Assert(delegateType.IsGenericType == false, "delegateType.IsGenericType == false"); this.delegateType = delegateType; this.targetType = targetType; this.method = method; this.namingScope = namingScope; }
private IInvocationCreationContributor GetContributor(Type @delegate, MetaMethod method) { if (@delegate.IsGenericType == false) { return new InvocationWithDelegateContributor(@delegate, targetType, method, namingScope); } return new InvocationWithGenericDelegateContributor(@delegate, method, new FieldReference(InvocationMethods.ProxyObject)); }
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); }
private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options) { ModuleScope scope = emitter.ModuleScope; CacheKey key = new CacheKey(method.Method, WCFCompositionInvocationTypeGenerator.BaseType, null, null); Type invocation = scope.GetFromCache(key); if (invocation == null) { invocation = new WCFCompositionInvocationTypeGenerator(method.Method.DeclaringType, method, method.Method, false, null).Generate(emitter, options, base.namingScope).BuildType(); scope.RegisterInCache(key, invocation); } return invocation; }
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 )); }
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 override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { if (!method.Proxyable) { return(new MinimialisticMethodGenerator(method, overrideMethod)); } var invocation = GetInvocationType(method, @class, options); return(new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), invocation, getTargetExpression, overrideMethod, null)); }
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); }
private Type BuildInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) { var methodInfo = method.Method; if (!method.HasTarget) { return new ClassInvocationTypeGenerator(targetType, method, null) .Generate(@class, options, namingScope) .BuildType(); } var callback = CreateCallbackMethod(@class, methodInfo, method.MethodOnTarget); return new ClassInvocationTypeGenerator(callback.DeclaringType, method, callback) .Generate(@class, options, namingScope) .BuildType(); }
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); }
private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) { Type[] invocationInterfaces; ModuleScope scope = @class.ModuleScope; if (this.canChangeTarget) { invocationInterfaces = new Type[] { typeof(IInvocation), typeof(IChangeProxyTarget) }; } else { invocationInterfaces = new Type[] { typeof(IInvocation) }; } CacheKey key = new CacheKey(method.Method, WCFCompositionInvocationTypeGenerator.BaseType, invocationInterfaces, null); Type invocation = scope.GetFromCache(key); if (invocation == null) { invocation = new WCFCompositionInvocationTypeGenerator(method.Method.DeclaringType, method, method.Method, this.canChangeTarget, null).Generate(@class, options, base.namingScope).BuildType(); scope.RegisterInCache(key, invocation); } return invocation; }
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)); }
private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options) { var scope = emitter.ModuleScope; var key = new CacheKey(method.Method, InterfaceInvocationTypeGenerator.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 InterfaceInvocationTypeGenerator(method.Method.DeclaringType, method, method.Method, false) .Generate(emitter, options, namingScope).BuildType(); scope.RegisterInCache(key, invocation); return invocation; }
protected abstract MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod);
public InterfaceInvocationTypeGenerator(Type target, MetaMethod method, MethodInfo callback, bool canChangeTarget) : base(target, method, callback, canChangeTarget) { }
private Type GetDelegateType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) { var scope = @class.ModuleScope; var key = new CacheKey( typeof(Delegate), targetType, new[] { method.MethodOnTarget.ReturnType } .Concat(ArgumentsUtil.GetTypes(method.MethodOnTarget.GetParameters())). ToArray(), null); var type = scope.GetFromCache(key); if (type != null) return type; type = new DelegateTypeGenerator(method, targetType) .Generate(@class, options, namingScope) .BuildType(); scope.RegisterInCache(key, type); return type; }
private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) { // NOTE: No caching since invocation is tied to this specific proxy type via its invocation method return BuildInvocationType(method, @class, options); }
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); }
private bool ExplicitlyImplementedInterfaceMethod(MetaMethod method) { return method.MethodOnTarget.IsPrivate; }
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); } } }
public void AddMethod(MetaMethod method) { methods.Add(method); }
public OptionallyForwardingMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod, GetTargetReferenceDelegate getTargetReference) : base(method, overrideMethod) { this.getTargetReference = getTargetReference; }