User: xtoff
Date: 2009/11/28 05:43 PM
Added:
/DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
MixinContributor.cs
Removed:
/DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
EmptyMixinContributor.cs, MixinContributor.cs, MixinContributorBase.cs
Modified:
/DynamicProxy/trunk/src/Castle.DynamicProxy/
Castle.DynamicProxy-vs2008.csproj
/DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
ClassProxyInstanceContributor.cs, InterfaceProxyWithoutTargetContributor.cs,
ProxyInstanceContributor.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
ClassProxyGenerator.cs, InterfaceProxyWithTargetGenerator.cs,
InterfaceProxyWithTargetInterfaceGenerator.cs,
InterfaceProxyWithoutTargetGenerator.cs
Log:
- some clean up in code, removed duplication
File Changes:
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/
=======================================================
File [modified]: Castle.DynamicProxy-vs2008.csproj
Delta lines: +0 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ClassProxyInstanceContributor.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ClassProxyInstanceContributor.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -177,7 +177,6 @@
throw new ArgumentException(message);
}
- // TODO: This should be removed
methodsToSkip.Add(getObjectDataMethod);
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
====================================================================
File [modified]: ClassProxyInstanceContributor.cs
Delta lines: +0 -41
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/EmptyMixinContributor.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/EmptyMixinContributor.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -1,41 +0,0 @@
-// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-namespace Castle.DynamicProxy.Contributors
-{
- using System;
- using System.Diagnostics;
- using Generators.Emitters;
-
- class EmptyMixinContributor : MixinContributorBase
- {
- public override void
CollectElementsToProxy(IProxyGenerationHook hook)
- {
-
- }
-
- public EmptyMixinContributor(Type @interface)
- {
- if (@interface == null) throw new
ArgumentNullException("interface");
- // TODO: this method is likely to be moved to the
interface
- Debug.Assert(@interface.IsInterface,
"@interface.IsInterface", "Should be adding mapping only...");
- mixinInterface = @interface;
- }
-
- public override void Generate(ClassEmitter @class,
ProxyGenerationOptions options)
- {
- field = BuildTargetField(@class, mixinInterface);
- }
- }
-}
File [removed]: EmptyMixinContributor.cs
Delta lines: +3 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -128,7 +128,9 @@
}
else
{
- generator = new
MinimialisticMethodGenerator(method, createMethod,
GeneratorUtil.ObtainInterfaceMethodAttributes);
+ generator = new
MinimialisticMethodGenerator(method,
+
createMethod,
+
GeneratorUtil.ObtainInterfaceMethodAttributes);
}
File [modified]: InterfaceProxyWithoutTargetContributor.cs
Delta lines: +0 -176
===================================================================
--- DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributor.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributor.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -1,176 +0,0 @@
-// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-namespace Castle.DynamicProxy.Contributors
-{
- using System;
- using System.Diagnostics;
-
- using Castle.Core.Interceptor;
- using Castle.DynamicProxy.Generators;
- using Castle.DynamicProxy.Generators.Emitters;
-
- public class MixinContributor : MixinContributorBase
- {
- private readonly bool canChangeTarget;
- private readonly INamingScope namingScope;
- private MembersCollector target;
-
- public MixinContributor(Type @interface, INamingScope
namingScope)
- : this(@interface, namingScope, false)
- {
- }
-
- public MixinContributor(Type @interface, INamingScope
namingScope, bool canChangeTarget)
- {
- if (@interface == null) throw new
ArgumentNullException("interface");
-
- Debug.Assert(@interface.IsInterface,
"@interface.IsInterface", "Should be adding mapping only...");
-
- this.namingScope = namingScope;
- this.canChangeTarget = canChangeTarget;
- mixinInterface = @interface;
- }
-
- public override void
CollectElementsToProxy(IProxyGenerationHook hook)
- {
- Debug.Assert(hook != null, "hook != null");
- // TODO: once tokens for method on target are obtained
dynamically
- // this should be changed to InterfaceMembersCollector
- var item = new
InterfaceMembersCollector(mixinInterface);
- item.CollectMembersToProxy(hook);
- target = item;
-
- }
-
- public override void Generate(ClassEmitter @class,
ProxyGenerationOptions options)
- {
- field = BuildTargetField(@class, mixinInterface);
-
- 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);
- }
-
- }
-
-
- private void ImplementEvent(ClassEmitter emitter,
EventToGenerate @event, ProxyGenerationOptions options)
- {
- @event.BuildEventEmitter(emitter);
- var adder = @event.Adder;
- ImplementMethod(adder, emitter, options,
@event.Emitter.CreateAddMethod);
- var remover = @event.Remover;
- ImplementMethod(remover, emitter, options,
@event.Emitter.CreateRemoveMethod);
-
- }
-
- private void ImplementProperty(ClassEmitter emitter,
PropertyToGenerate property, ProxyGenerationOptions options)
- {
- property.BuildPropertyEmitter(emitter);
- if (property.CanRead)
- {
- var getter = property.Getter;
- ImplementMethod(getter, emitter, options,
- (name, atts) =>
property.Emitter.CreateGetMethod(name, atts));
- }
-
- if (property.CanWrite)
- {
- var setter = property.Setter;
- ImplementMethod(setter, emitter, options,
- (name, atts) =>
property.Emitter.CreateSetMethod(name, atts));
- }
- }
-
- private void ImplementMethod(MethodToGenerate method,
ClassEmitter emitter, ProxyGenerationOptions options, CreateMethodDelegate
createMethod)
- {
- MethodGenerator generator;
- if (method.Proxyable)
- {
- var invocation = GetInvocationType(method,
emitter, options);
-
- generator = new
MethodWithInvocationGenerator(method,
-
emitter.GetField("__interceptors"),
-
invocation,
-
getTargetExpression,
-
createMethod,
-
GeneratorUtil.ObtainInterfaceMethodAttributes);
- }
- else
- {
- generator = new
ForwardingMethodGenerator(method,
-
createMethod,
- (c,
i) => field);
- }
- var proxyMethod = generator.Generate(emitter, options,
namingScope);
- foreach (var attribute in
AttributeUtil.GetNonInheritableAttributes(method.Method))
- {
- proxyMethod.DefineCustomAttribute(attribute);
- }
- }
-
- private Type GetInvocationType(MethodToGenerate method,
ClassEmitter emitter, ProxyGenerationOptions options)
- {
- var scope = emitter.ModuleScope;
- Type[] interfaces = Type.EmptyTypes;
- if (canChangeTarget)
- {
- interfaces = new[] { typeof(IChangeProxyTarget)
};
- }
- var key = new CacheKey(method.Method,
InterfaceInvocationTypeGenerator.BaseType, interfaces, 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,
-
canChangeTarget)
- .Generate(emitter, options,
namingScope).BuildType();
-
- scope.RegisterInCache(key, invocation);
-
- return invocation;
- }
-
- public void SetGetTargetExpression(GetTargetExpressionDelegate
getTarget)
- {
- getTargetExpression = getTarget;
- }
- }
-}
File [removed]: MixinContributor.cs
Delta lines: +0 -51
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributorBase.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributorBase.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -1,51 +0,0 @@
-// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-namespace Castle.DynamicProxy.Contributors
-{
- using System;
-
- using Castle.DynamicProxy.Generators.Emitters;
- using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
-
- //TODO: this class should be factored out as soon as we get rid of the
need for BackingField property
- public abstract class MixinContributorBase : ITypeContributor
- {
- protected FieldReference field;
-
- protected Type mixinInterface;
- protected GetTargetExpressionDelegate getTargetExpression;
-
- protected MixinContributorBase()
- {
- getTargetExpression = (c, i) =>
BackingField.ToExpression();
- }
-
- public FieldReference BackingField
- {
- get
- {
- return field;
- }
- }
-
- protected FieldReference BuildTargetField(ClassEmitter emitter,
Type type)
- {
- return emitter.CreateField("__mixin_" +
type.FullName.Replace(".", "_"), type);
- }
-
- public abstract void
CollectElementsToProxy(IProxyGenerationHook hook);
- public abstract void Generate(ClassEmitter @class,
ProxyGenerationOptions options);
- }
-}
File [added]: MixinContributor.cs
Delta lines: None
None
File [removed]: MixinContributorBase.cs
Delta lines: +0 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ProxyInstanceContributor.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ProxyInstanceContributor.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -15,7 +15,6 @@
namespace Castle.DynamicProxy.Contributors
{
using System;
- using System.Reflection;
#if !SILVERLIGHT
using System.Runtime.Serialization;
File [modified]: ProxyInstanceContributor.cs
Delta lines: +10 -11
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/ClassProxyGenerator.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/ClassProxyGenerator.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -122,9 +122,9 @@
contributor.Generate(emitter,
ProxyGenerationOptions);
// TODO: redo it
- if (contributor is MixinContributorBase)
+ if (contributor is MixinContributor)
{
- constructorArguments.Add((contributor
as MixinContributorBase).BackingField);
+
constructorArguments.AddRange((contributor as MixinContributor).Fields);
}
}
@@ -165,7 +165,7 @@
var targetInterfaces =
TypeUtil.GetAllInterfaces(targetType);
var additionalInterfaces =
TypeUtil.GetAllInterfaces(interfaces);
// 2. then mixins
- var mixins = new List<MixinContributorBase>();
+ var mixins = new MixinContributor(namingScope, false);
if (ProxyGenerationOptions.HasMixins)
{
foreach (var mixinInterface in
ProxyGenerationOptions.MixinData.MixinInterfaces)
@@ -179,15 +179,14 @@
proxyTarget.AddInterfaceToProxy(mixinInterface);
}
// we do not intercept the
interface
- mixins.Add(new
EmptyMixinContributor(mixinInterface));
+
mixins.AddEmptyInterface(mixinInterface);
}
else
{
if
(!typeImplementerMapping.ContainsKey(mixinInterface))
{
- var mixin = new
MixinContributor(mixinInterface, namingScope);
- mixins.Add(mixin);
-
SafeAddMapping(mixinInterface, mixin, typeImplementerMapping);
+
mixins.AddInterfaceToProxy(mixinInterface);
+
SafeAddMapping(mixinInterface, mixins, typeImplementerMapping);
}
}
}
@@ -229,10 +228,10 @@
}
var contributorsList = new List<ITypeContributor>();
contributorsList.Add(proxyTarget);
- foreach (var mixin in mixins)
- {
- contributorsList.Add(mixin);
- }
+ //foreach (var mixin in mixins)
+ //{
+ contributorsList.Add(mixins);
+ //}
contributorsList.Add(additionalInterfacesContributor);
contributorsList.Add(proxyInstance);
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
==================================================================
File [modified]: ClassProxyGenerator.cs
Delta lines: +11 -17
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -148,9 +148,9 @@
contributor.Generate(emitter,
ProxyGenerationOptions);
// TODO: redo it
- if(contributor is MixinContributorBase)
+ if (contributor is MixinContributor)
{
- ctorArguments.Add((contributor as
MixinContributorBase).BackingField);
+ ctorArguments.AddRange((contributor as
MixinContributor).Fields);
}
}
@@ -222,7 +222,7 @@
protected IDictionary<Type, ITypeContributor>
GetTypeImplementerMapping(Type[] interfaces, Type proxyTargetType, out
IEnumerable<ITypeContributor> contributors, INamingScope namingScope)
{
IDictionary<Type, ITypeContributor>
typeImplementerMapping = new Dictionary<Type, ITypeContributor>();
- var mixins = new List<MixinContributorBase>();
+ var mixins = new
MixinContributor(namingScope,AllowChangeTarget);
// Order of interface precedence:
// 1. first target
var targetInterfaces =
TypeUtil.GetAllInterfaces(proxyTargetType);
@@ -235,7 +235,6 @@
{
foreach (var mixinInterface in
ProxyGenerationOptions.MixinData.MixinInterfaces)
{
- object mixinInstance =
ProxyGenerationOptions.MixinData.GetMixinInstance(mixinInterface);
if
(targetInterfaces.Contains(mixinInterface))
{
// OK, so the target implements
this interface. We now do one of two things:
@@ -245,15 +244,14 @@
AddMapping(mixinInterface, target, typeImplementerMapping);
}
// we do not intercept the
interface
- mixins.Add(new
EmptyMixinContributor(mixinInterface));
+
mixins.AddEmptyInterface(mixinInterface);
}
else
{
if
(!typeImplementerMapping.ContainsKey(mixinInterface))
{
- var mixin =
GetContributorForMixin(namingScope, mixinInterface, mixinInstance);
- mixins.Add(mixin);
-
typeImplementerMapping.Add(mixinInterface, mixin);
+
mixins.AddInterfaceToProxy(mixinInterface);
+
typeImplementerMapping.Add(mixinInterface, mixins);
}
}
}
@@ -285,21 +283,16 @@
var list = new List<ITypeContributor>();
list.Add(target);
list.Add(additionalInterfacesContributor);
- foreach (var mixin in mixins)
- {
- list.Add(mixin);
- }
+ //foreach (var mixin in mixins)
+ //{
+ list.Add(mixins);
+ //}
list.Add(instance);
contributors = list;
return typeImplementerMapping;
}
- protected virtual MixinContributor
GetContributorForMixin(INamingScope namingScope, Type mixinInterface, object
mixinInstance)
- {
- return new MixinContributor(mixinInterface,
namingScope);
- }
-
protected virtual InterfaceProxyWithoutTargetContributor
GetContributorForAdditionalInterfaces(INamingScope namingScope)
{
return new
InterfaceProxyWithoutTargetContributor(namingScope, (c, m) =>
NullExpression.Instance);
@@ -310,6 +303,7 @@
base.SafeAddMapping(@interface, implementer, mapping);
if(implementer is InterfaceProxyTargetContributor)
{
+ // TODO: REMOVE IT!
(implementer as
InterfaceProxyTargetContributor).AddInterfaceToProxy(@interface);
}
File [modified]: InterfaceProxyWithTargetGenerator.cs
Delta lines: +0 -10
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -36,16 +36,6 @@
return contributor;
}
- protected override MixinContributor
GetContributorForMixin(INamingScope namingScope, Type mixinInterface, object
mixinInstance)
- {
- var contributorForMixin = new
MixinContributor(mixinInterface, namingScope,true);
- contributorForMixin.SetGetTargetExpression(
- (c, m) => new NullCoalescingOperatorExpression(
- new
AsTypeReference(c.GetField("__target"), mixinInterface).ToExpression(),
-
contributorForMixin.BackingField.ToExpression()));
- return contributorForMixin;
- }
-
protected override InterfaceProxyWithoutTargetContributor
GetContributorForAdditionalInterfaces(INamingScope namingScope)
{
File [modified]: InterfaceProxyWithTargetInterfaceGenerator.cs
Delta lines: +2 -2
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs
2009-11-28 23:15:47 UTC (rev 6368)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs
2009-11-29 00:42:54 UTC (rev 6369)
@@ -69,9 +69,9 @@
contributor.Generate(emitter,
ProxyGenerationOptions);
// TODO: redo it
- if (contributor is MixinContributorBase)
+ if (contributor is MixinContributor)
{
- mixinFieldsList.Add((contributor as
MixinContributorBase).BackingField);
+ mixinFieldsList.AddRange((contributor
as MixinContributor).Fields);
}
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.