From fd80bc595ca1059f6927a5853d943bcb52195239 Mon Sep 17 00:00:00 2001 From: stakx Date: Thu, 2 Jul 2020 22:22:03 +0200 Subject: [PATCH 1/2] Remove `options` where they aren't needed --- .../ClassProxyInstanceContributor.cs | 2 +- .../ClassProxyTargetContributor.cs | 24 ++++++++--------- .../ClassProxyWithTargetTargetContributor.cs | 24 ++++++++--------- .../Contributors/CompositeTypeContributor.cs | 26 +++++++++---------- .../Contributors/ITypeContributor.cs | 2 +- .../InterfaceProxyTargetContributor.cs | 7 +++-- ...rfaceProxyWithOptionalTargetContributor.cs | 3 +-- .../InterfaceProxyWithoutTargetContributor.cs | 7 +++-- .../Contributors/MixinContributor.cs | 11 ++++---- .../Contributors/ProxyInstanceContributor.cs | 2 +- .../Generators/BaseProxyGenerator.cs | 10 +++---- .../Generators/ClassProxyGenerator.cs | 2 +- .../ClassProxyWithTargetGenerator.cs | 2 +- .../CompositionInvocationTypeGenerator.cs | 1 - .../Generators/DelegateTypeGenerator.cs | 2 +- .../Emitters/AbstractTypeEmitter.cs | 4 +-- .../Generators/ForwardingMethodGenerator.cs | 2 +- .../DynamicProxy/Generators/IGenerator.cs | 2 +- .../InheritanceInvocationTypeGenerator.cs | 1 - .../InterfaceProxyWithTargetGenerator.cs | 2 +- .../InterfaceProxyWithoutTargetGenerator.cs | 2 +- .../Generators/InvocationTypeGenerator.cs | 9 +++---- .../Generators/MethodGenerator.cs | 6 ++--- .../MethodWithInvocationGenerator.cs | 2 +- .../MinimialisticMethodGenerator.cs | 2 +- .../OptionallyForwardingMethodGenerator.cs | 2 +- 26 files changed, 73 insertions(+), 86 deletions(-) diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyInstanceContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyInstanceContributor.cs index 7560206478..5471762bea 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyInstanceContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyInstanceContributor.cs @@ -54,7 +54,7 @@ protected override Reference GetTargetReference(ClassEmitter emitter) return SelfReference.Self; } - public override void Generate(ClassEmitter @class, ProxyGenerationOptions options) + public override void Generate(ClassEmitter @class) { var interceptors = @class.GetField("__interceptors"); #if FEATURE_SERIALIZATION diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs index 46b4dba5a6..c23a31b7c9 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs @@ -57,7 +57,6 @@ protected override IEnumerable CollectElementsToProxyInternal( } protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { if (methodsToSkip.Contains(method.Method)) @@ -73,10 +72,10 @@ protected override IEnumerable CollectElementsToProxyInternal( if (ExplicitlyImplementedInterfaceMethod(method)) { - return ExplicitlyImplementedInterfaceMethodGenerator(method, @class, options, overrideMethod); + return ExplicitlyImplementedInterfaceMethodGenerator(method, @class, overrideMethod); } - var invocation = GetInvocationType(method, @class, options); + var invocation = GetInvocationType(method, @class); GetTargetExpressionDelegate getTargetTypeExpression = (c, m) => new TypeTokenExpression(targetType); @@ -89,7 +88,7 @@ protected override IEnumerable CollectElementsToProxyInternal( null); } - private Type BuildInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) + private Type BuildInvocationType(MetaMethod method, ClassEmitter @class) { var methodInfo = method.Method; if (!method.HasTarget) @@ -97,14 +96,14 @@ private Type BuildInvocationType(MetaMethod method, ClassEmitter @class, ProxyGe return new InheritanceInvocationTypeGenerator(targetType, method, null, null) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType(); } var callback = CreateCallbackMethod(@class, methodInfo, method.MethodOnTarget); return new InheritanceInvocationTypeGenerator(callback.DeclaringType, method, callback, null) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType(); } @@ -141,13 +140,12 @@ private bool ExplicitlyImplementedInterfaceMethod(MetaMethod method) } private MethodGenerator ExplicitlyImplementedInterfaceMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { - var @delegate = GetDelegateType(method, @class, options); + var @delegate = GetDelegateType(method, @class); var contributor = GetContributor(@delegate, method); var invocation = new InheritanceInvocationTypeGenerator(targetType, method, null, contributor) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType(); return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), @@ -168,7 +166,7 @@ private IInvocationCreationContributor GetContributor(Type @delegate, MetaMethod new FieldReference(InvocationMethods.ProxyObject)); } - private Type GetDelegateType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) + private Type GetDelegateType(MetaMethod method, ClassEmitter @class) { var scope = @class.ModuleScope; var key = new CacheKey( @@ -181,14 +179,14 @@ private Type GetDelegateType(MetaMethod method, ClassEmitter @class, ProxyGenera return scope.TypeCache.GetOrAddWithoutTakingLock(key, _ => new DelegateTypeGenerator(method, targetType) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType()); } - private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) + private Type GetInvocationType(MetaMethod method, ClassEmitter @class) { // NOTE: No caching since invocation is tied to this specific proxy type via its invocation method - return BuildInvocationType(method, @class, options); + return BuildInvocationType(method, @class); } } } \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs index e0ae84665e..588a0a2b4b 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs @@ -56,7 +56,6 @@ protected override IEnumerable CollectElementsToProxyInternal( } protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { if (methodsToSkip.Contains(method.Method)) @@ -72,10 +71,10 @@ protected override IEnumerable CollectElementsToProxyInternal( if (IsDirectlyAccessible(method) == false) { - return IndirectlyCalledMethodGenerator(method, @class, options, overrideMethod); + return IndirectlyCalledMethodGenerator(method, @class, overrideMethod); } - var invocation = GetInvocationType(method, @class, options); + var invocation = GetInvocationType(method, @class); return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), @@ -85,14 +84,14 @@ protected override IEnumerable CollectElementsToProxyInternal( null); } - private Type BuildInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) + private Type BuildInvocationType(MetaMethod method, ClassEmitter @class) { if (!method.HasTarget) { return new InheritanceInvocationTypeGenerator(targetType, method, null, null) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType(); } return new CompositionInvocationTypeGenerator(method.Method.DeclaringType, @@ -100,7 +99,7 @@ private Type BuildInvocationType(MetaMethod method, ClassEmitter @class, ProxyGe method.Method, false, null) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType(); } @@ -115,7 +114,7 @@ private IInvocationCreationContributor GetContributor(Type @delegate, MetaMethod new FieldReference(InvocationMethods.CompositionInvocationTarget)); } - private Type GetDelegateType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) + private Type GetDelegateType(MetaMethod method, ClassEmitter @class) { var scope = @class.ModuleScope; var key = new CacheKey( @@ -128,11 +127,11 @@ private Type GetDelegateType(MetaMethod method, ClassEmitter @class, ProxyGenera return scope.TypeCache.GetOrAddWithoutTakingLock(key, _ => new DelegateTypeGenerator(method, targetType) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType()); } - private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) + private Type GetInvocationType(MetaMethod method, ClassEmitter @class) { var scope = @class.ModuleScope; var invocationInterfaces = new[] { typeof(IInvocation) }; @@ -141,17 +140,16 @@ private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGene // no locking required as we're already within a lock - return scope.TypeCache.GetOrAddWithoutTakingLock(key, _ => BuildInvocationType(method, @class, options)); + return scope.TypeCache.GetOrAddWithoutTakingLock(key, _ => BuildInvocationType(method, @class)); } private MethodGenerator IndirectlyCalledMethodGenerator(MetaMethod method, ClassEmitter proxy, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { - var @delegate = GetDelegateType(method, proxy, options); + var @delegate = GetDelegateType(method, proxy); var contributor = GetContributor(@delegate, method); var invocation = new CompositionInvocationTypeGenerator(targetType, method, null, false, contributor) - .Generate(proxy, options, namingScope) + .Generate(proxy, namingScope) .BuildType(); return new MethodWithInvocationGenerator(method, proxy.GetField("__interceptors"), diff --git a/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs index c44d412101..c6d64a5bd4 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs @@ -70,7 +70,7 @@ public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) protected abstract IEnumerable CollectElementsToProxyInternal(IProxyGenerationHook hook); - public virtual void Generate(ClassEmitter @class, ProxyGenerationOptions options) + public virtual void Generate(ClassEmitter @class) { foreach (var method in methods) { @@ -81,18 +81,17 @@ public virtual void Generate(ClassEmitter @class, ProxyGenerationOptions options ImplementMethod(method, @class, - options, @class.CreateMethod); } foreach (var property in properties) { - ImplementProperty(@class, property, options); + ImplementProperty(@class, property); } foreach (var @event in events) { - ImplementEvent(@class, @event, options); + ImplementEvent(@class, @event); } } @@ -106,41 +105,40 @@ public void AddInterfaceToProxy(Type @interface) interfaces.Add(@interface); } - private void ImplementEvent(ClassEmitter emitter, MetaEvent @event, ProxyGenerationOptions options) + private void ImplementEvent(ClassEmitter emitter, MetaEvent @event) { @event.BuildEventEmitter(emitter); - ImplementMethod(@event.Adder, emitter, options, @event.Emitter.CreateAddMethod); - ImplementMethod(@event.Remover, emitter, options, @event.Emitter.CreateRemoveMethod); + ImplementMethod(@event.Adder, emitter, @event.Emitter.CreateAddMethod); + ImplementMethod(@event.Remover, emitter, @event.Emitter.CreateRemoveMethod); } - private void ImplementProperty(ClassEmitter emitter, MetaProperty property, ProxyGenerationOptions options) + private void ImplementProperty(ClassEmitter emitter, MetaProperty property) { property.BuildPropertyEmitter(emitter); if (property.CanRead) { - ImplementMethod(property.Getter, emitter, options, property.Emitter.CreateGetMethod); + ImplementMethod(property.Getter, emitter, property.Emitter.CreateGetMethod); } if (property.CanWrite) { - ImplementMethod(property.Setter, emitter, options, property.Emitter.CreateSetMethod); + ImplementMethod(property.Setter, emitter, property.Emitter.CreateSetMethod); } } protected abstract MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod); - private void ImplementMethod(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, + private void ImplementMethod(MetaMethod method, ClassEmitter @class, OverrideMethodDelegate overrideMethod) { { - var generator = GetMethodGenerator(method, @class, options, overrideMethod); + var generator = GetMethodGenerator(method, @class, overrideMethod); if (generator == null) { return; } - var proxyMethod = generator.Generate(@class, options, namingScope); + var proxyMethod = generator.Generate(@class, namingScope); foreach (var attribute in method.Method.GetNonInheritableAttributes()) { proxyMethod.DefineCustomAttribute(attribute.Builder); diff --git a/src/Castle.Core/DynamicProxy/Contributors/ITypeContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ITypeContributor.cs index 8e46f5ca5d..fba0486f21 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ITypeContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ITypeContributor.cs @@ -24,6 +24,6 @@ internal interface ITypeContributor { void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model); - void Generate(ClassEmitter @class, ProxyGenerationOptions options); + void Generate(ClassEmitter @class); } } \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyTargetContributor.cs index e6bd0c8232..9eff629c84 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyTargetContributor.cs @@ -54,7 +54,6 @@ protected virtual MembersCollector GetCollectorForInterface(Type @interface) } protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { if (!method.Proxyable) @@ -64,7 +63,7 @@ protected virtual MembersCollector GetCollectorForInterface(Type @interface) (c, m) => c.GetField("__target")); } - var invocation = GetInvocationType(method, @class, options); + var invocation = GetInvocationType(method, @class); return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), @@ -74,7 +73,7 @@ protected virtual MembersCollector GetCollectorForInterface(Type @interface) null); } - private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options) + private Type GetInvocationType(MetaMethod method, ClassEmitter @class) { var scope = @class.ModuleScope; @@ -98,7 +97,7 @@ private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGene method.Method, canChangeTarget, null) - .Generate(@class, options, namingScope) + .Generate(@class, namingScope) .BuildType()); } } diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs index 13f8864a4c..ed59da253c 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs @@ -30,7 +30,6 @@ internal class InterfaceProxyWithOptionalTargetContributor : InterfaceProxyWitho } protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { if (!method.Proxyable) @@ -38,7 +37,7 @@ internal class InterfaceProxyWithOptionalTargetContributor : InterfaceProxyWitho return new OptionallyForwardingMethodGenerator(method, overrideMethod, getTargetReference); } - return base.GetMethodGenerator(method, @class, options, overrideMethod); + return base.GetMethodGenerator(method, @class, overrideMethod); } } } \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs index f7433a0812..223b2393f3 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs @@ -44,7 +44,6 @@ protected override IEnumerable CollectElementsToProxyInternal( } protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { if (!method.Proxyable) @@ -52,7 +51,7 @@ protected override IEnumerable CollectElementsToProxyInternal( return new MinimialisticMethodGenerator(method, overrideMethod); } - var invocation = GetInvocationType(method, @class, options); + var invocation = GetInvocationType(method, @class); return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), invocation, @@ -61,7 +60,7 @@ protected override IEnumerable CollectElementsToProxyInternal( null); } - private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options) + private Type GetInvocationType(MetaMethod method, ClassEmitter emitter) { var scope = emitter.ModuleScope; Type[] invocationInterfaces; @@ -83,7 +82,7 @@ private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGen method.Method, canChangeTarget, null) - .Generate(emitter, options, namingScope) + .Generate(emitter, namingScope) .BuildType()); } } diff --git a/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs index ffb89aeb07..b5647c0e22 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs @@ -54,7 +54,7 @@ public void AddEmptyInterface(Type @interface) empty.Add(@interface); } - public override void Generate(ClassEmitter @class, ProxyGenerationOptions options) + public override void Generate(ClassEmitter @class) { foreach (var @interface in interfaces) { @@ -66,7 +66,7 @@ public override void Generate(ClassEmitter @class, ProxyGenerationOptions option fields[emptyInterface] = BuildTargetField(@class, emptyInterface); } - base.Generate(@class, options); + base.Generate(@class); } protected override IEnumerable CollectElementsToProxyInternal(IProxyGenerationHook hook) @@ -89,7 +89,6 @@ protected override IEnumerable CollectElementsToProxyInternal( } protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, - ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) { if (!method.Proxyable) @@ -99,7 +98,7 @@ protected override IEnumerable CollectElementsToProxyInternal( (c, i) => fields[i.DeclaringType]); } - var invocation = GetInvocationType(method, @class, options); + var invocation = GetInvocationType(method, @class); return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), invocation, @@ -126,7 +125,7 @@ private FieldReference BuildTargetField(ClassEmitter @class, Type type) return @class.CreateField(namingScope.GetUniqueName(name), type); } - private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options) + private Type GetInvocationType(MetaMethod method, ClassEmitter emitter) { var scope = emitter.ModuleScope; Type[] invocationInterfaces; @@ -148,7 +147,7 @@ private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGen method.Method, canChangeTarget, null) - .Generate(emitter, options, namingScope) + .Generate(emitter, namingScope) .BuildType()); } } diff --git a/src/Castle.Core/DynamicProxy/Contributors/ProxyInstanceContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ProxyInstanceContributor.cs index 2ee8f777f9..1b4a82e4d9 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ProxyInstanceContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ProxyInstanceContributor.cs @@ -50,7 +50,7 @@ private Expression GetTargetReferenceExpression(ClassEmitter emitter) return GetTargetReference(emitter).ToExpression(); } - public virtual void Generate(ClassEmitter @class, ProxyGenerationOptions options) + public virtual void Generate(ClassEmitter @class) { var interceptors = @class.GetField("__interceptors"); #if FEATURE_SERIALIZATION diff --git a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs index 8a47217652..5e41aced18 100644 --- a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs @@ -174,22 +174,22 @@ protected void CreateSelectorField(ClassEmitter emitter) protected virtual void CreateTypeAttributes(ClassEmitter emitter) { - emitter.AddCustomAttributes(ProxyGenerationOptions); + emitter.AddCustomAttributes(ProxyGenerationOptions.AdditionalAttributes); #if FEATURE_SERIALIZATION emitter.DefineCustomAttribute(new object[] { targetType }); #endif } - protected void EnsureOptionsOverrideEqualsAndGetHashCode(ProxyGenerationOptions options) + protected void EnsureOptionsOverrideEqualsAndGetHashCode() { if (Logger.IsWarnEnabled) { // Check the proxy generation hook - if (!OverridesEqualsAndGetHashCode(options.Hook.GetType())) + if (!OverridesEqualsAndGetHashCode(ProxyGenerationOptions.Hook.GetType())) { Logger.WarnFormat("The IProxyGenerationHook type {0} does not override both Equals and GetHashCode. " + "If these are not correctly overridden caching will fail to work causing performance problems.", - options.Hook.GetType().FullName); + ProxyGenerationOptions.Hook.GetType().FullName); } // Interceptor selectors no longer need to override Equals and GetHashCode @@ -381,7 +381,7 @@ private protected Type ObtainProxyType(CacheKey cacheKey, Func(); foreach (var contributor in contributors) { - contributor.Generate(emitter, ProxyGenerationOptions); + contributor.Generate(emitter); // TODO: redo it var mixinContributor = contributor as MixinContributor; diff --git a/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs index 210e0f7986..b2ac11014f 100644 --- a/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs @@ -192,7 +192,7 @@ private Type GenerateType(string name, INamingScope namingScope) foreach (var contributor in contributors) { - contributor.Generate(emitter, ProxyGenerationOptions); + contributor.Generate(emitter); // TODO: redo it if (contributor is MixinContributor) diff --git a/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs index 9d45da9494..3f554d2581 100644 --- a/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs @@ -34,7 +34,6 @@ internal class CompositionInvocationTypeGenerator : InvocationTypeGenerator } protected override ArgumentReference[] GetBaseCtorArguments(Type targetFieldType, - ProxyGenerationOptions proxyGenerationOptions, out ConstructorInfo baseConstructor) { baseConstructor = InvocationMethods.CompositionInvocationConstructor; diff --git a/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs index 868391dfdb..d0d806c89b 100644 --- a/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs @@ -38,7 +38,7 @@ public DelegateTypeGenerator(MetaMethod method, Type targetType) this.targetType = targetType; } - public AbstractTypeEmitter Generate(ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope) + public AbstractTypeEmitter Generate(ClassEmitter @class, INamingScope namingScope) { var emitter = GetEmitter(@class, namingScope); BuildConstructor(emitter); diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs index 58cf26e75b..d7c47c6e7c 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs @@ -88,9 +88,9 @@ public TypeBuilder TypeBuilder get { return typebuilder; } } - public void AddCustomAttributes(ProxyGenerationOptions proxyGenerationOptions) + public void AddCustomAttributes(IEnumerable additionalAttributes) { - foreach (var attribute in proxyGenerationOptions.AdditionalAttributes) + foreach (var attribute in additionalAttributes) { typebuilder.SetCustomAttribute(attribute.Builder); } diff --git a/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs index 895ef0a85e..200c6bd32b 100644 --- a/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs @@ -30,7 +30,7 @@ internal class ForwardingMethodGenerator : MethodGenerator } protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, - ProxyGenerationOptions options, INamingScope namingScope) + INamingScope namingScope) { var targetReference = getTargetReference(@class, MethodToOverride); var arguments = ArgumentsUtil.ConvertToArgumentReferenceExpression(MethodToOverride.GetParameters()); diff --git a/src/Castle.Core/DynamicProxy/Generators/IGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/IGenerator.cs index 9085ed859b..c7b7ebf1b7 100644 --- a/src/Castle.Core/DynamicProxy/Generators/IGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/IGenerator.cs @@ -18,6 +18,6 @@ namespace Castle.DynamicProxy.Generators internal interface IGenerator { - T Generate(ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope); + T Generate(ClassEmitter @class, INamingScope namingScope); } } \ No newline at end of file diff --git a/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs index fe88e3361d..dbdcb43163 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs @@ -33,7 +33,6 @@ internal class InheritanceInvocationTypeGenerator : InvocationTypeGenerator } protected override ArgumentReference[] GetBaseCtorArguments(Type targetFieldType, - ProxyGenerationOptions proxyGenerationOptions, out ConstructorInfo baseConstructor) { baseConstructor = InvocationMethods.InheritanceInvocationConstructor; diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs index e903c0d527..19b70170d6 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs @@ -124,7 +124,7 @@ protected virtual Type GenerateType(string typeName, Type proxyTargetType, Type[ foreach (var contributor in contributors) { - contributor.Generate(emitter, ProxyGenerationOptions); + contributor.Generate(emitter); // TODO: redo it if (contributor is MixinContributor) diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs index 8654e5ec6e..ca459e3491 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs @@ -73,7 +73,7 @@ protected override string GeneratorType foreach (var contributor in contributors) { - contributor.Generate(emitter, ProxyGenerationOptions); + contributor.Generate(emitter); // TODO: redo it if (contributor is MixinContributor) diff --git a/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs index c8818ccfc0..db47084841 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs @@ -48,14 +48,13 @@ internal abstract class InvocationTypeGenerator : IGenerator /// protected abstract ArgumentReference[] GetBaseCtorArguments(Type targetFieldType, - ProxyGenerationOptions proxyGenerationOptions, out ConstructorInfo baseConstructor); protected abstract Type GetBaseType(); protected abstract FieldReference GetTargetReference(); - public AbstractTypeEmitter Generate(ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope) + public AbstractTypeEmitter Generate(ClassEmitter @class, INamingScope namingScope) { var methodInfo = method.Method; @@ -71,7 +70,7 @@ public AbstractTypeEmitter Generate(ClassEmitter @class, ProxyGenerationOptions // targetType cannot be a generic type definition (YET!) invocation.CopyGenericParametersFromMethod(methodInfo); - CreateConstructor(invocation, options); + CreateConstructor(invocation); var targetField = GetTargetReference(); if (canChangeTarget) @@ -211,10 +210,10 @@ private void AssignBackByRefArguments(MethodEmitter invokeMethodOnTarget, Dictio invokeMethodOnTarget.CodeBuilder.AddStatement(new EndExceptionBlockStatement()); } - private void CreateConstructor(AbstractTypeEmitter invocation, ProxyGenerationOptions options) + private void CreateConstructor(AbstractTypeEmitter invocation) { ConstructorInfo baseConstructor; - var baseCtorArguments = GetBaseCtorArguments(targetType, options, out baseConstructor); + var baseCtorArguments = GetBaseCtorArguments(targetType, out baseConstructor); var constructor = CreateConstructor(invocation, baseCtorArguments); constructor.CodeBuilder.InvokeBaseConstructor(baseConstructor, baseCtorArguments); diff --git a/src/Castle.Core/DynamicProxy/Generators/MethodGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/MethodGenerator.cs index b8c61adbca..e03dadf178 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MethodGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MethodGenerator.cs @@ -41,12 +41,12 @@ protected MethodInfo MethodToOverride } protected abstract MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, - ProxyGenerationOptions options, INamingScope namingScope); + INamingScope namingScope); - public MethodEmitter Generate(ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope) + public MethodEmitter Generate(ClassEmitter @class, INamingScope namingScope) { var methodEmitter = overrideMethod(method.Name, method.Attributes, MethodToOverride); - var proxiedMethod = BuildProxiedMethodBody(methodEmitter, @class, options, namingScope); + var proxiedMethod = BuildProxiedMethodBody(methodEmitter, @class, namingScope); if (MethodToOverride.DeclaringType.IsInterface) { diff --git a/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs index 66a53517f3..d3dcdfca8f 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs @@ -69,7 +69,7 @@ protected FieldReference BuildMethodInterceptorsField(ClassEmitter @class, Metho return methodInterceptors; } - protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope) + protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, INamingScope namingScope) { var invocationType = invocation; diff --git a/src/Castle.Core/DynamicProxy/Generators/MinimialisticMethodGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/MinimialisticMethodGenerator.cs index 3b76efcb25..7183c11052 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MinimialisticMethodGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MinimialisticMethodGenerator.cs @@ -28,7 +28,7 @@ public MinimialisticMethodGenerator(MetaMethod method, OverrideMethodDelegate ov } protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, - ProxyGenerationOptions options, INamingScope namingScope) + INamingScope namingScope) { InitOutParameters(emitter, MethodToOverride.GetParameters()); diff --git a/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs index 7dc2130efd..843ec31727 100644 --- a/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs @@ -34,7 +34,7 @@ internal class OptionallyForwardingMethodGenerator : MethodGenerator } protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, - ProxyGenerationOptions options, INamingScope namingScope) + INamingScope namingScope) { var targetReference = getTargetReference(@class, MethodToOverride); From b6ebedaa6dc1e86497886cb1c611a51456ec8067 Mon Sep 17 00:00:00 2001 From: stakx Date: Thu, 2 Jul 2020 22:59:20 +0200 Subject: [PATCH 2/2] Inject `options` into proxy generators via ctor --- .../DynamicProxy/DefaultProxyBuilder.cs | 16 +++++++------- .../Generators/BaseProxyGenerator.cs | 21 ++++--------------- .../Generators/ClassProxyGenerator.cs | 11 ++++------ .../ClassProxyWithTargetGenerator.cs | 4 +--- .../InterfaceProxyWithTargetGenerator.cs | 14 +++++-------- ...erfaceProxyWithTargetInterfaceGenerator.cs | 4 ++-- .../InterfaceProxyWithoutTargetGenerator.cs | 3 ++- .../Serialization/ProxyObjectReference.cs | 12 +++++------ 8 files changed, 32 insertions(+), 53 deletions(-) diff --git a/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs b/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs index 341e2dff1c..2616cdd39f 100644 --- a/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs +++ b/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs @@ -65,8 +65,8 @@ public Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesT AssertValidTypes(additionalInterfacesToProxy, nameof(additionalInterfacesToProxy)); AssertValidMixins(options, nameof(options)); - var generator = new ClassProxyGenerator(scope, classToProxy) { Logger = logger }; - return generator.GenerateCode(additionalInterfacesToProxy, options); + var generator = new ClassProxyGenerator(scope, classToProxy, options) { Logger = logger }; + return generator.GenerateCode(additionalInterfacesToProxy); } public Type CreateClassProxyTypeWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy, @@ -89,8 +89,8 @@ public Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesT AssertValidTypes(additionalInterfacesToProxy, nameof(additionalInterfacesToProxy)); AssertValidMixins(options, nameof(options)); - var generator = new InterfaceProxyWithTargetGenerator(scope, interfaceToProxy) { Logger = logger }; - return generator.GenerateCode(targetType, additionalInterfacesToProxy, options); + var generator = new InterfaceProxyWithTargetGenerator(scope, interfaceToProxy, options) { Logger = logger }; + return generator.GenerateCode(targetType, additionalInterfacesToProxy); } public Type CreateInterfaceProxyTypeWithTargetInterface(Type interfaceToProxy, Type[] additionalInterfacesToProxy, @@ -100,8 +100,8 @@ public Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesT AssertValidTypes(additionalInterfacesToProxy, nameof(additionalInterfacesToProxy)); AssertValidMixins(options, nameof(options)); - var generator = new InterfaceProxyWithTargetInterfaceGenerator(scope, interfaceToProxy) { Logger = logger }; - return generator.GenerateCode(interfaceToProxy, additionalInterfacesToProxy, options); + var generator = new InterfaceProxyWithTargetInterfaceGenerator(scope, interfaceToProxy, options) { Logger = logger }; + return generator.GenerateCode(interfaceToProxy, additionalInterfacesToProxy); } public Type CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, @@ -111,8 +111,8 @@ public Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesT AssertValidTypes(additionalInterfacesToProxy, nameof(additionalInterfacesToProxy)); AssertValidMixins(options, nameof(options)); - var generator = new InterfaceProxyWithoutTargetGenerator(scope, interfaceToProxy) { Logger = logger }; - return generator.GenerateCode(typeof(object), additionalInterfacesToProxy, options); + var generator = new InterfaceProxyWithoutTargetGenerator(scope, interfaceToProxy, options) { Logger = logger }; + return generator.GenerateCode(typeof(object), additionalInterfacesToProxy); } private void AssertValidMixins(ProxyGenerationOptions options, string paramName) diff --git a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs index 5e41aced18..76c4de2e2d 100644 --- a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs @@ -42,10 +42,12 @@ internal abstract class BaseProxyGenerator private ILogger logger = NullLogger.Instance; private ProxyGenerationOptions proxyGenerationOptions; - protected BaseProxyGenerator(ModuleScope scope, Type targetType) + protected BaseProxyGenerator(ModuleScope scope, Type targetType, ProxyGenerationOptions proxyGenerationOptions) { this.scope = scope; this.targetType = targetType; + this.proxyGenerationOptions = proxyGenerationOptions; + this.proxyGenerationOptions.Initialize(); } public ILogger Logger @@ -56,22 +58,7 @@ public ILogger Logger protected ProxyGenerationOptions ProxyGenerationOptions { - get - { - if (proxyGenerationOptions == null) - { - throw new InvalidOperationException("ProxyGenerationOptions must be set before being retrieved."); - } - return proxyGenerationOptions; - } - set - { - if (proxyGenerationOptions != null) - { - throw new InvalidOperationException("ProxyGenerationOptions can only be set once."); - } - proxyGenerationOptions = value; - } + get { return proxyGenerationOptions; } } protected ModuleScope Scope diff --git a/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs index 8e31ef3ccd..55e1b56276 100644 --- a/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs @@ -27,21 +27,18 @@ namespace Castle.DynamicProxy.Generators internal class ClassProxyGenerator : BaseProxyGenerator { - public ClassProxyGenerator(ModuleScope scope, Type targetType) : base(scope, targetType) + public ClassProxyGenerator(ModuleScope scope, Type targetType, ProxyGenerationOptions options) + : base(scope, targetType, options) { CheckNotGenericTypeDefinition(targetType, "targetType"); EnsureDoesNotImplementIProxyTargetAccessor(targetType, "targetType"); } - public Type GenerateCode(Type[] interfaces, ProxyGenerationOptions options) + public Type GenerateCode(Type[] interfaces) { - // make sure ProxyGenerationOptions is initialized - options.Initialize(); - interfaces = TypeUtil.GetAllInterfaces(interfaces); CheckNotGenericTypeDefinitions(interfaces, "interfaces"); - ProxyGenerationOptions = options; - var cacheKey = new CacheKey(targetType, interfaces, options); + var cacheKey = new CacheKey(targetType, interfaces, ProxyGenerationOptions); return ObtainProxyType(cacheKey, (n, s) => GenerateType(n, interfaces, s)); } diff --git a/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs index b2ac11014f..ad7cc9f7b3 100644 --- a/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs @@ -34,14 +34,12 @@ internal class ClassProxyWithTargetGenerator : BaseProxyGenerator public ClassProxyWithTargetGenerator(ModuleScope scope, Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) - : base(scope, classToProxy) + : base(scope, classToProxy, options) { CheckNotGenericTypeDefinition(targetType, "targetType"); EnsureDoesNotImplementIProxyTargetAccessor(targetType, "targetType"); CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy"); - options.Initialize(); - ProxyGenerationOptions = options; this.additionalInterfacesToProxy = TypeUtil.GetAllInterfaces(additionalInterfacesToProxy); } diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs index 19b70170d6..7efecd44b8 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs @@ -32,8 +32,8 @@ internal class InterfaceProxyWithTargetGenerator : BaseProxyGenerator { protected FieldReference targetField; - public InterfaceProxyWithTargetGenerator(ModuleScope scope, Type @interface) - : base(scope, @interface) + public InterfaceProxyWithTargetGenerator(ModuleScope scope, Type @interface, ProxyGenerationOptions options) + : base(scope, @interface, options) { CheckNotGenericTypeDefinition(@interface, "@interface"); } @@ -48,18 +48,14 @@ protected virtual string GeneratorType get { return ProxyTypeConstants.InterfaceWithTarget; } } - public Type GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options) + public Type GenerateCode(Type proxyTargetType, Type[] interfaces) { - // make sure ProxyGenerationOptions is initialized - options.Initialize(); - CheckNotGenericTypeDefinition(proxyTargetType, "proxyTargetType"); CheckNotGenericTypeDefinitions(interfaces, "interfaces"); - EnsureValidBaseType(options.BaseTypeForInterfaceProxy); - ProxyGenerationOptions = options; + EnsureValidBaseType(ProxyGenerationOptions.BaseTypeForInterfaceProxy); interfaces = TypeUtil.GetAllInterfaces(interfaces); - var cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, options); + var cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, ProxyGenerationOptions); return ObtainProxyType(cacheKey, (n, s) => GenerateType(n, proxyTargetType, interfaces, s)); } diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs index ac7448342e..cb99ab5148 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs @@ -26,8 +26,8 @@ namespace Castle.DynamicProxy.Generators internal class InterfaceProxyWithTargetInterfaceGenerator : InterfaceProxyWithTargetGenerator { - public InterfaceProxyWithTargetInterfaceGenerator(ModuleScope scope, Type @interface) - : base(scope, @interface) + public InterfaceProxyWithTargetInterfaceGenerator(ModuleScope scope, Type @interface, ProxyGenerationOptions options) + : base(scope, @interface, options) { } diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs index ca459e3491..909d5861c2 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs @@ -25,7 +25,8 @@ namespace Castle.DynamicProxy.Generators internal class InterfaceProxyWithoutTargetGenerator : InterfaceProxyWithTargetGenerator { - public InterfaceProxyWithoutTargetGenerator(ModuleScope scope, Type @interface) : base(scope, @interface) + public InterfaceProxyWithoutTargetGenerator(ModuleScope scope, Type @interface, ProxyGenerationOptions options) + : base(scope, @interface, options) { } diff --git a/src/Castle.Core/DynamicProxy/Serialization/ProxyObjectReference.cs b/src/Castle.Core/DynamicProxy/Serialization/ProxyObjectReference.cs index c36f97eff4..7dace03f4b 100644 --- a/src/Castle.Core/DynamicProxy/Serialization/ProxyObjectReference.cs +++ b/src/Castle.Core/DynamicProxy/Serialization/ProxyObjectReference.cs @@ -144,15 +144,15 @@ public object RecreateInterfaceProxy(string generatorType) InterfaceProxyWithTargetGenerator generator; if (generatorType == ProxyTypeConstants.InterfaceWithTarget) { - generator = new InterfaceProxyWithTargetGenerator(scope, @interface); + generator = new InterfaceProxyWithTargetGenerator(scope, @interface, proxyGenerationOptions); } else if (generatorType == ProxyTypeConstants.InterfaceWithoutTarget) { - generator = new InterfaceProxyWithoutTargetGenerator(scope, @interface); + generator = new InterfaceProxyWithoutTargetGenerator(scope, @interface, proxyGenerationOptions); } else if (generatorType == ProxyTypeConstants.InterfaceWithTargetInterface) { - generator = new InterfaceProxyWithTargetInterfaceGenerator(scope, @interface); + generator = new InterfaceProxyWithTargetInterfaceGenerator(scope, @interface, proxyGenerationOptions); } else { @@ -162,14 +162,14 @@ public object RecreateInterfaceProxy(string generatorType) generatorType)); } - var proxyType = generator.GenerateCode(targetType, interfaces, proxyGenerationOptions); + var proxyType = generator.GenerateCode(targetType, interfaces); return FormatterServices.GetSafeUninitializedObject(proxyType); } public object RecreateClassProxy() { - var generator = new ClassProxyGenerator(scope, baseType); - var proxyType = generator.GenerateCode(interfaces, proxyGenerationOptions); + var generator = new ClassProxyGenerator(scope, baseType, proxyGenerationOptions); + var proxyType = generator.GenerateCode(interfaces); return InstantiateClassProxy(proxyType); }