User: xtoff
Date: 2009/12/29 06:06 AM

Modified:
 /DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
  CompositeTypeContributor.cs, InterfaceProxyWithoutTargetContributor.cs
 /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
  ClassProxyGenerator.cs, InterfaceProxyWithTargetGenerator.cs, 
InterfaceProxyWithoutTargetGenerator.cs

Log:
 - changed InterfaceProxyWithoutTargetContributor to inherit from 
CompositeTypeContributor

File Changes:

Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
====================================================================

File [modified]: CompositeTypeContributor.cs
Delta lines: +15 -97
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs
   2009-12-29 01:01:13 UTC (rev 6536)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs
   2009-12-29 13:06:00 UTC (rev 6537)
@@ -15,26 +15,22 @@
 namespace Castle.DynamicProxy.Contributors
 {
        using System;
-       using System.Collections.Generic;
        using System.Diagnostics;
 
        using Castle.DynamicProxy.Generators;
        using Castle.DynamicProxy.Generators.Emitters;
 
-       public class InterfaceProxyWithoutTargetContributor : ITypeContributor
+       public class InterfaceProxyWithoutTargetContributor : 
CompositeTypeContributor
        {
-               private readonly IList<MembersCollector> targets = new 
List<MembersCollector>();
-               private readonly IList<Type> interfaces = new List<Type>();
-               private readonly INamingScope namingScope;
                private readonly GetTargetExpressionDelegate 
getTargetExpression;
 
                public InterfaceProxyWithoutTargetContributor(INamingScope 
namingScope, GetTargetExpressionDelegate getTarget)
+                       : base(namingScope)
                {
-                       this.namingScope = namingScope;
                        getTargetExpression = getTarget;
                }
 
-               public void CollectElementsToProxy(IProxyGenerationHook hook)
+               public override void 
CollectElementsToProxy(IProxyGenerationHook hook)
                {
                        Debug.Assert(hook != null, "hook != null");
                        foreach (var @interface in interfaces)
@@ -45,108 +41,30 @@
                        }
                }
 
-
-               public void AddInterfaceMapping(Type @interface)
+               protected override MethodGenerator 
GetMethodGenerator(MethodToGenerate method, ClassEmitter @class, 
ProxyGenerationOptions options, CreateMethodDelegate createMethod)
                {
-                       // TODO: this method is likely to be moved to the 
interface
-                       Debug.Assert(@interface != null, "@interface == null", 
"Shouldn't be adding empty interfaces...");
-                       Debug.Assert(@interface.IsInterface, 
"@interface.IsInterface", "Should be adding interfaces only...");
-                       Debug.Assert(!interfaces.Contains(@interface), 
"!interfaces.Contains(@interface)", "Shouldn't be adding same interface 
twice...");
-                       interfaces.Add(@interface);
-               }
-
-               public void Generate(ClassEmitter @class, 
ProxyGenerationOptions options)
-               {
-                       foreach (var target in targets)
+                       if (!method.Proxyable)
                        {
-                               foreach (var method in target.Methods)
-                               {
-                                       if (!method.Standalone)
-                                       {
-                                               continue;
-                                       }
-
-                                       ImplementMethod(method,
-                                                                       @class,
-                                                                       options,
-                                                                       
@class.CreateMethod);
-                               }
-
-                               foreach (var property in target.Properties)
-                               {
-                                       ImplementProperty(@class, property, 
options);
-                               }
-
-                               foreach (var @event in target.Events)
-                               {
-                                       ImplementEvent(@class, @event, options);
-                               }
+                               return new MinimialisticMethodGenerator(method,
+                                                                               
                                createMethod,
+                                                                               
                                GeneratorUtil.ObtainInterfaceMethodAttributes);
                        }
-               }
 
-               private void ImplementEvent(ClassEmitter emitter, 
EventToGenerate @event, ProxyGenerationOptions options)
-               {
-                       @event.BuildEventEmitter(emitter);
-                       var method = @event.Adder;
-                       ImplementMethod(method, emitter, options, 
@event.Emitter.CreateAddMethod);
-                       var method1 = @event.Remover;
-                       ImplementMethod(method1, emitter, options, 
@event.Emitter.CreateRemoveMethod);
-
+                       var invocation = GetInvocationType(method, @class, 
options);
+                       return new MethodWithInvocationGenerator(method,
+                                                                               
                         @class.GetField("__interceptors"),
+                                                                               
                         invocation,
+                                                                               
                         getTargetExpression,
+                                                                               
                         createMethod,
+                                                                               
                         GeneratorUtil.ObtainInterfaceMethodAttributes);
                }
 
-               private void ImplementProperty(ClassEmitter emitter, 
PropertyToGenerate property, ProxyGenerationOptions options)
-               {
-                       property.BuildPropertyEmitter(emitter);
-                       if (property.CanRead)
-                       {
-                               var method = property.Getter;
-                               ImplementMethod(method, emitter, options,
-                                                               (name, atts) => 
property.Emitter.CreateGetMethod(name, atts));
-                       }
-
-                       if (property.CanWrite)
-                       {
-                               var method = property.Setter;
-                               ImplementMethod(method, emitter, options,
-                                                               (name, atts) => 
property.Emitter.CreateSetMethod(name, atts));
-                       }
-               }
-
-               private void ImplementMethod(MethodToGenerate method, 
ClassEmitter @class, ProxyGenerationOptions options, CreateMethodDelegate 
createMethod)
-               {
-                       MethodGenerator generator;
-                       if (method.Proxyable)
-                       {
-                               var invocation = GetInvocationType(method, 
@class, options);
-
-                               generator = new 
MethodWithInvocationGenerator(method,
-                                                                             
@class.GetField("__interceptors"),
-                                                                             
invocation,
-                                                                             
getTargetExpression,
-                                                                             
createMethod,
-                                                                             
GeneratorUtil.ObtainInterfaceMethodAttributes);
-                       }
-                       else
-                       {
-                               generator = new 
MinimialisticMethodGenerator(method,
-                                                                            
createMethod,
-                                                                            
GeneratorUtil.ObtainInterfaceMethodAttributes);
-                       }
-
-                       var proxiedMethod = generator.Generate(@class, options, 
namingScope);
-                       foreach (var attribute in 
AttributeUtil.GetNonInheritableAttributes(method.Method))
-                       {
-                               proxiedMethod.DefineCustomAttribute(attribute);
-                       }
-               }
-
                private Type GetInvocationType(MethodToGenerate 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)

File [modified]: InterfaceProxyWithoutTargetContributor.cs
Delta lines: +1 -1
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/ClassProxyGenerator.cs    
    2009-12-29 01:01:13 UTC (rev 6536)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/ClassProxyGenerator.cs    
    2009-12-29 13:06:00 UTC (rev 6537)
@@ -208,7 +208,7 @@
                                }
                                else if 
(ProxyGenerationOptions.MixinData.ContainsMixin(@interface) == false)
                                {
-                                       
additionalInterfacesContributor.AddInterfaceMapping(@interface);
+                                       
additionalInterfacesContributor.AddInterfaceToProxy(@interface);
                                        AddMapping(@interface, 
additionalInterfacesContributor, typeImplementerMapping);
                                }

Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
==================================================================

File [modified]: ClassProxyGenerator.cs
Delta lines: +1 -1
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs
  2009-12-29 01:01:13 UTC (rev 6536)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs
  2009-12-29 13:06:00 UTC (rev 6537)
@@ -268,7 +268,7 @@
                                
if(typeImplementerMapping.ContainsKey(@interface)) continue;
                                
if(ProxyGenerationOptions.MixinData.ContainsMixin(@interface)) continue;
 
-                               
additionalInterfacesContributor.AddInterfaceMapping(@interface);
+                               
additionalInterfacesContributor.AddInterfaceToProxy(@interface);
                                SafeAddMapping(@interface, 
additionalInterfacesContributor, typeImplementerMapping);
                        }

File [modified]: InterfaceProxyWithTargetGenerator.cs
Delta lines: +1 -1
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs
       2009-12-29 01:01:13 UTC (rev 6536)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs
       2009-12-29 13:06:00 UTC (rev 6537)
@@ -33,7 +33,7 @@
                        var contributor = new 
InterfaceProxyWithoutTargetContributor(namingScope, (c, m) => 
NullExpression.Instance);
                        foreach (var @interface in 
TypeUtil.GetAllInterfaces(targetType))
                        {
-                               contributor.AddInterfaceMapping(@interface);
+                               contributor.AddInterfaceToProxy(@interface);
                                SafeAddMapping(@interface, contributor, 
interfaceTypeImplementerMapping);
                        }

File [modified]: InterfaceProxyWithoutTargetGenerator.cs
Delta lines: +0 -0
===================================================================

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-commits?hl=en.


Reply via email to