User: xtoff
Date: 2009/11/10 10:59 AM
Added:
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
MethodWithCallbackGenerator.cs
Removed:
/DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
MethodWithCallbackGenerator.cs
Modified:
/DynamicProxy/trunk/src/Castle.DynamicProxy/
AttributeUtil.cs, Castle.DynamicProxy-vs2008.csproj, ModuleScope.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
ForwardingMethodGenerator.cs, InterfaceProxyInstanceContributor.cs,
MixinContributor.cs, MixinContributorBase.cs, ProxyInstanceContributor.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
AttributeDisassembler.cs, AttributesToAvoidReplicating.cs,
BaseProxyGenerator.cs, ClassProxyGenerator.cs, InterfaceMethodGenerator.cs,
InvocationTypeGenerator.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/
ArgumentsUtil.cs, GenericUtil.cs, MethodEmitter.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/CodeBuilders/
AbstractCodeBuilder.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/
AssignArgumentStatement.cs, AssignArrayStatement.cs, ExpressionStatement.cs,
NewArrayExpression.cs, NewInstanceExpression.cs
Log:
- some minor cleanup and removed duplication
File Changes:
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/
=======================================================
File [modified]: AttributeUtil.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Castle.DynamicProxy-vs2008.csproj
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Castle.DynamicProxy-vs2008.csproj
2009-11-10 17:59:08 UTC (rev 6310)
@@ -108,7 +108,7 @@
<Compile Include="Contributors\Delegates.cs" />
<Compile Include="Contributors\EmptyMixinContributor.cs" />
<Compile Include="Contributors\InterfaceProxyWithoutTargetContributor.cs"
/>
- <Compile Include="Contributors\MethodWithCallbackGenerator.cs" />
+ <Compile Include="Generators\MethodWithCallbackGenerator.cs" />
<Compile Include="Contributors\MixinContributorBase.cs" />
<Compile Include="Contributors\ForwardingMethodGenerator.cs" />
File [modified]: Castle.DynamicProxy-vs2008.csproj
Delta lines: +3 -9
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ForwardingMethodGenerator.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ForwardingMethodGenerator.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -65,20 +65,14 @@
private MethodEmitter ImplementProxiedMethod(MethodEmitter
emitter, ClassEmitter @class)
{
emitter.CopyParametersAndReturnTypeFrom(method.Method,
@class);
- var targetReference =
getTargetReference(@class,method.Method);
- var parameters = method.Method.GetParameters();
- var arguments = new Expression[parameters.Length];
- for (int index = 0; index < parameters.Length; index++)
- {
- var parameter = parameters[index];
- arguments[index] = new ReferenceExpression(new
ArgumentReference(parameter.ParameterType, index + 1));
- }
+ var targetReference = getTargetReference(@class,
method.Method);
+ var arguments =
ArgumentsUtil.ConvertToArgumentReferenceExpression(method.Method.GetParameters());
emitter.CodeBuilder.AddStatement(new ReturnStatement(
new
MethodInvocationExpression(
targetReference,
method.Method,
-
arguments) {VirtualCall = true}));
+
arguments) { VirtualCall = true }));
return emitter;
}
File [modified]: ModuleScope.cs
Delta lines: +0 -0
===================================================================
Directory:
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/CodeBuilders/
========================================================================================
File [modified]: AbstractCodeBuilder.cs
Delta lines: +0 -15
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/GenericUtil.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/GenericUtil.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -239,20 +239,5 @@
return paramType;
}
-
- public static Type[] ExtractParameterTypes(ParameterInfo[]
baseMethodParameters)
- {
- Type[] newParameters = new
Type[baseMethodParameters.Length];
-
- for (int i = 0; i < baseMethodParameters.Length; i++)
- {
- ParameterInfo param = baseMethodParameters[i];
- Type paramType = param.ParameterType;
-
- newParameters[i] = paramType;
- }
-
- return newParameters;
- }
}
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
====================================================================
File [modified]: ForwardingMethodGenerator.cs
Delta lines: +5 -5
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyInstanceContributor.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyInstanceContributor.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -15,12 +15,12 @@
namespace Castle.DynamicProxy.Contributors
{
using System;
- using Generators;
- using Generators.Emitters;
- using Generators.Emitters.CodeBuilders;
- using Generators.Emitters.SimpleAST;
- using Tokens;
+ using Castle.DynamicProxy.Generators.Emitters;
+ using Castle.DynamicProxy.Generators.Emitters.CodeBuilders;
+ using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
+ using Castle.DynamicProxy.Tokens;
+
public class InterfaceProxyInstanceContributor :
ProxyInstanceContributor
{
File [modified]: InterfaceProxyInstanceContributor.cs
Delta lines: +0 -308
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MethodWithCallbackGenerator.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MethodWithCallbackGenerator.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -1,308 +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 System.Reflection;
- using System.Reflection.Emit;
- using System.Xml.Serialization;
- using Castle.Core.Interceptor;
- using Castle.DynamicProxy.Generators;
- using Castle.DynamicProxy.Generators.Emitters;
- using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
- using Castle.DynamicProxy.Tokens;
-
- public class MethodWithCallbackGenerator:MethodGenerator
- {
- private readonly MethodToGenerate method;
- private readonly NestedClassEmitter invocation;
- private readonly Reference interceptors;
- private readonly CreateMethodDelegate createMethod;
-
- public MethodWithCallbackGenerator(MethodToGenerate method,
NestedClassEmitter invocation, Reference interceptors, CreateMethodDelegate
createMethod)
- {
- this.method = method;
- this.invocation = invocation;
- this.interceptors = interceptors;
- this.createMethod = createMethod;
- }
-
- public override MethodEmitter Generate(ClassEmitter @class,
ProxyGenerationOptions options, INamingScope namingScope)
- {
- string name;
- var atts = ObtainMethodAttributes(out name);
- var methodEmitter = createMethod(name, atts);
- var proxiedMethod =
ImplementProxiedMethod(methodEmitter,
- @class,
- options,
- namingScope);
-
- if (method.Method.DeclaringType.IsInterface)
- {
-
@class.TypeBuilder.DefineMethodOverride(methodEmitter.MethodBuilder,
method.Method);
-
- }
- return proxiedMethod;
- }
-
- public MethodEmitter ImplementProxiedMethod(MethodEmitter
emitter, ClassEmitter @class, ProxyGenerationOptions options,INamingScope
namingScope)
- {
- var methodInfo = method.Method;
- emitter.CopyParametersAndReturnTypeFrom(methodInfo,
@class);
-
- TypeReference[] dereferencedArguments =
IndirectReference.WrapIfByRef(emitter.Arguments);
-
- Type iinvocation = invocation.TypeBuilder;
-
- Trace.Assert(methodInfo.IsGenericMethod ==
iinvocation.IsGenericTypeDefinition);
- bool isGenericInvocationClass = false;
- Type[] genericMethodArgs = Type.EmptyTypes;
- if (methodInfo.IsGenericMethod)
- {
- // bind generic method arguments to
invocation's type arguments
- genericMethodArgs =
emitter.MethodBuilder.GetGenericArguments();
- iinvocation =
iinvocation.MakeGenericType(genericMethodArgs);
- isGenericInvocationClass = true;
- }
-
- Expression methodInfoTokenExp;
-
- string tokenFieldName;
- if (methodInfo.IsGenericMethod)
- {
- // Not in the cache: generic method
- MethodInfo genericMethod =
methodInfo.MakeGenericMethod(genericMethodArgs);
-
- tokenFieldName =
namingScope.GetUniqueName("token_" + methodInfo.Name);
- methodInfoTokenExp = new
MethodTokenExpression(genericMethod);
- }
- else
- {
-
- var methodTokenField =
@class.CreateStaticField(namingScope.GetUniqueName("token_" + methodInfo.Name),
-
typeof (MethodInfo));
-
@class.ClassConstructor.CodeBuilder.AddStatement(new
AssignStatement(methodTokenField, new MethodTokenExpression(methodInfo)));
- tokenFieldName =
methodTokenField.Reference.Name;
- methodInfoTokenExp =
methodTokenField.ToExpression();
- }
-
- LocalReference invocationImplLocal =
emitter.CodeBuilder.DeclareLocal(iinvocation);
-
- // TODO: Initialize iinvocation instance with ordinary
arguments and in and out arguments
-
- ConstructorInfo constructor =
invocation.Constructors[0].ConstructorBuilder;
- if (isGenericInvocationClass)
- {
- constructor =
TypeBuilder.GetConstructor(iinvocation, constructor);
- }
-
- Expression targetMethod = methodInfoTokenExp;
- Expression interfaceMethod = NullExpression.Instance;
-
-
- NewInstanceExpression newInvocImpl;
-
- // TODO: this is not always true. Should be passed
explicitly as ctor parameter
- Type targetType = methodInfo.DeclaringType;
- Debug.Assert(targetType != null, "targetType != null");
- if (options.Selector == null)
- {
- newInvocImpl = //actual contructor call
- new NewInstanceExpression(constructor,
-
SelfReference.Self.ToExpression(),
-
SelfReference.Self.ToExpression(),
-
interceptors.ToExpression(),
- // NOTE: there's no need to cache type
token
- // profiling showed that it gives no
real performance gain
-
new TypeTokenExpression(targetType),
-
targetMethod,
-
interfaceMethod,
-
new ReferencesToObjectArrayExpression(dereferencedArguments));
- }
- else
- {
- // Create the field to store the selected
interceptors for this method if an InterceptorSelector is specified
- // NOTE: If no interceptors are returned,
should we invoke the base.Method directly? Looks like we should not.
- var methodInterceptors =
@class.CreateField(string.Format("{0}_interceptors", tokenFieldName),
-
typeof (IInterceptor[]), false);
-
-#if !SILVERLIGHT
-
@class.DefineCustomAttributeFor<XmlIgnoreAttribute>(methodInterceptors);
-#endif
-
- MethodInvocationExpression selector =
- new
MethodInvocationExpression(@class.GetField("proxyGenerationOptions"),
-
ProxyGenerationOptionsMethods.GetSelector);
- selector.VirtualCall = true;
-
- newInvocImpl = //actual contructor call
- new NewInstanceExpression(constructor,
-
SelfReference.Self.ToExpression(),
-
SelfReference.Self.ToExpression(),
-
interceptors.ToExpression(),
-
new TypeTokenExpression(targetType),
-
targetMethod,
-
interfaceMethod,
-
new ReferencesToObjectArrayExpression(dereferencedArguments),
-
selector,
-
new AddressOfReferenceExpression(methodInterceptors));
- }
-
- emitter.CodeBuilder.AddStatement(new
AssignStatement(invocationImplLocal, newInvocImpl));
-
- if (methodInfo.ContainsGenericParameters)
- {
- EmitLoadGenricMethodArguments(emitter,
methodInfo.MakeGenericMethod(genericMethodArgs), invocationImplLocal);
- }
-
- emitter.CodeBuilder.AddStatement(
- new ExpressionStatement(new
MethodInvocationExpression(invocationImplLocal, InvocationMethods.Proceed)));
-
- CopyOutAndRefParameters(dereferencedArguments,
invocationImplLocal, methodInfo, emitter);
-
- if (methodInfo.ReturnType != typeof(void))
- {
- // Emit code to return with cast from
ReturnValue
- MethodInvocationExpression getRetVal =
- new
MethodInvocationExpression(invocationImplLocal,
InvocationMethods.GetReturnValue);
-
- emitter.CodeBuilder.AddStatement(
- new ReturnStatement(new
ConvertExpression(emitter.ReturnType, getRetVal)));
- }
- else
- {
- emitter.CodeBuilder.AddStatement(new
ReturnStatement());
- }
-
- return emitter;
- }
-
- private static void CopyOutAndRefParameters(TypeReference[]
dereferencedArguments, LocalReference invocationImplLocal, MethodInfo method,
MethodEmitter methodEmitter)
- {
- ParameterInfo[] parameters = method.GetParameters();
- bool hasByRefParam = false;
- for (int i = 0; i < parameters.Length; i++)
- {
- if (parameters[i].ParameterType.IsByRef)
- hasByRefParam = true;
- }
- if (!hasByRefParam)
- return; //saving the need to create locals if
there is no need
- LocalReference invocationArgs =
methodEmitter.CodeBuilder.DeclareLocal(typeof(object[]));
- methodEmitter.CodeBuilder.AddStatement(
- new AssignStatement(invocationArgs,
- new
MethodInvocationExpression(invocationImplLocal, InvocationMethods.GetArguments)
- )
- );
- for (int i = 0; i < parameters.Length; i++)
- {
- if (parameters[i].ParameterType.IsByRef)
- {
- methodEmitter.CodeBuilder.AddStatement(
- new
AssignStatement(dereferencedArguments[i],
-
new ConvertExpression(dereferencedArguments[i].Type,
-
new
LoadRefArrayElementExpression(i, invocationArgs)
-
)
- ));
- }
- }
- }
-
- private void EmitLoadGenricMethodArguments(MethodEmitter
methodEmitter, MethodInfo method,
-
LocalReference invocationImplLocal)
- {
-#if SILVERLIGHT
- Type[] genericParameters =
-
Castle.Core.Extensions.SilverlightExtensions.FindAll(method.GetGenericArguments(),
delegate(Type t) { return t.IsGenericParameter; });
-#else
- Type[] genericParameters =
Array.FindAll(method.GetGenericArguments(), t => t.IsGenericParameter);
-#endif
- LocalReference genericParamsArrayLocal =
methodEmitter.CodeBuilder.DeclareLocal(typeof(Type[]));
- methodEmitter.CodeBuilder.AddStatement(
- new AssignStatement(genericParamsArrayLocal,
new NewArrayExpression(genericParameters.Length, typeof(Type))));
-
- for (int i = 0; i < genericParameters.Length; ++i)
- {
- methodEmitter.CodeBuilder.AddStatement(
- new
AssignArrayStatement(genericParamsArrayLocal, i, new
TypeTokenExpression(genericParameters[i])));
- }
- methodEmitter.CodeBuilder.AddStatement(new
ExpressionStatement(
-
new MethodInvocationExpression(invocationImplLocal,
InvocationMethods.SetGenericMethodArguments,
-
new ReferenceExpression(
-
genericParamsArrayLocal))));
- }
-
- private bool IsInterfaceMethodForExplicitImplementation()
- {
- return method.Method.DeclaringType.IsInterface &&
- method.MethodOnTarget.IsFinal;
- }
-
- private MethodAttributes ObtainMethodAttributes(out string name)
- {
- var methodInfo = method.Method;
- MethodAttributes attributes = MethodAttributes.Virtual;
- if (IsInterfaceMethodForExplicitImplementation())
- {
- name = methodInfo.DeclaringType.Name + "." +
methodInfo.Name;
- attributes |= MethodAttributes.Private |
- MethodAttributes.HideBySig |
- MethodAttributes.NewSlot |
- MethodAttributes.Final;
- }
- else
- {
- if (method.Method.IsFinal)
- {
- attributes |= MethodAttributes.NewSlot;
- }
-
- if (methodInfo.IsPublic)
- {
- attributes |= MethodAttributes.Public;
- }
-
- if (methodInfo.IsHideBySig)
- {
- attributes |=
MethodAttributes.HideBySig;
- }
- if (InternalsHelper.IsInternal(methodInfo) &&
InternalsHelper.IsInternalToDynamicProxy(methodInfo.DeclaringType.Assembly))
- {
- attributes |= MethodAttributes.Assembly;
- }
- if (methodInfo.IsFamilyAndAssembly)
- {
- attributes |=
MethodAttributes.FamANDAssem;
- }
- else if (methodInfo.IsFamilyOrAssembly)
- {
- attributes |=
MethodAttributes.FamORAssem;
- }
- else if (methodInfo.IsFamily)
- {
- attributes |= MethodAttributes.Family;
- }
- name = methodInfo.Name;
- }
-
- if (method.Standalone == false)
- {
- attributes |= MethodAttributes.SpecialName;
- }
- return attributes;
- }
- }
-}
File [removed]: MethodWithCallbackGenerator.cs
Delta lines: +1 -1
===================================================================
--- DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributor.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributor.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -114,7 +114,7 @@
}
}
- private void ImplementMethod(MethodToGenerate method,
ClassEmitter emitter, ProxyGenerationOptions options, CreateMethodDelegate
createMethod, FieldReference target)
+ private void ImplementMethod(MethodToGenerate method,
ClassEmitter emitter, ProxyGenerationOptions options, CreateMethodDelegate
createMethod, Reference target)
{
MethodGenerator generator;
File [modified]: MixinContributor.cs
Delta lines: +3 -3
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributorBase.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributorBase.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -15,10 +15,10 @@
namespace Castle.DynamicProxy.Contributors
{
using System;
- using System.Reflection;
- using Generators.Emitters;
- using Generators.Emitters.SimpleAST;
+ 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
File [modified]: MixinContributorBase.cs
Delta lines: +2 -2
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ProxyInstanceContributor.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ProxyInstanceContributor.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -77,8 +77,8 @@
protected void ImplementGetObjectData(ClassEmitter emitter)
{
- ArgumentReference serializationInfo = new
ArgumentReference(typeof (SerializationInfo));
- ArgumentReference streamingContext = new
ArgumentReference(typeof (StreamingContext));
+ var serializationInfo = new ArgumentReference(typeof
(SerializationInfo));
+ var streamingContext = new ArgumentReference(typeof
(StreamingContext));
MethodEmitter getObjectData =
emitter.CreateMethod("GetObjectData",
typeof (void), serializationInfo, streamingContext);
File [modified]: ProxyInstanceContributor.cs
Delta lines: +6 -13
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/AttributeDisassembler.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/AttributeDisassembler.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
- using Castle.Core.Interceptor;
#if !SILVERLIGHT
[Serializable]
@@ -16,21 +15,15 @@
{
Type type = attribute.GetType();
- ConstructorInfo ctor;
- object[] ctorArgs;
-
- PropertyInfo[] properties;
- object[] propertyValues;
-
- FieldInfo[] fields;
- object[] fieldValues;
-
try
{
- ctorArgs = GetConstructorAndArgs(type,
attribute, out ctor);
+ ConstructorInfo ctor;
+ object[] ctorArgs = GetConstructorAndArgs(type,
attribute, out ctor);
var replicated = (Attribute)
Activator.CreateInstance(type, ctorArgs);
- propertyValues = GetPropertyValues(type, out
properties, attribute, replicated);
- fieldValues = GetFieldValues(type, out fields,
attribute, replicated);
+ PropertyInfo[] properties;
+ object[] propertyValues =
GetPropertyValues(type, out properties, attribute, replicated);
+ FieldInfo[] fields;
+ object[] fieldValues = GetFieldValues(type, out
fields, attribute, replicated);
return new CustomAttributeBuilder(ctor,
ctorArgs, properties, propertyValues, fields, fieldValues);
}
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/
===========================================================================
File [modified]: ArgumentsUtil.cs
Delta lines: +4 -10
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/CodeBuilders/AbstractCodeBuilder.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/CodeBuilders/AbstractCodeBuilder.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -22,9 +22,9 @@
public abstract class AbstractCodeBuilder
{
private bool isEmpty;
- private ILGenerator generator;
- private List<Statement> stmts;
- private List<Reference> ilmarkers;
+ private readonly ILGenerator generator;
+ private readonly List<Statement> stmts;
+ private readonly List<Reference> ilmarkers;
protected AbstractCodeBuilder(ILGenerator generator)
{
@@ -34,6 +34,7 @@
isEmpty = true;
}
+ //NOTE: should we make this obsolete if no one is using it?
public /*protected internal*/ ILGenerator Generator
{
get { return generator; }
@@ -53,13 +54,6 @@
return local;
}
-// public LabelReference CreateLabel()
-// {
-// LabelReference label = new LabelReference();
-// ilmarkers.Add(label);
-// return label;
-// }
-//
public /*protected internal*/ void SetNonEmpty()
{
File [modified]: GenericUtil.cs
Delta lines: +1 -8
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/MethodEmitter.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/MethodEmitter.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -116,14 +116,7 @@
public void SetParameters(Type[] paramTypes)
{
builder.SetParameters(paramTypes);
-
- arguments = new ArgumentReference[paramTypes.Length];
-
- for (int i = 0; i < paramTypes.Length; i++)
- {
- arguments[i] = new
ArgumentReference(paramTypes[i]);
- }
-
+ arguments =
ArgumentsUtil.ConvertToArgumentReference(paramTypes);
ArgumentsUtil.InitializeArgumentsByPosition(arguments,
MethodBuilder.IsStatic);
}
File [modified]: MethodEmitter.cs
Delta lines: +2 -2
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/AssignArgumentStatement.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/AssignArgumentStatement.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -18,8 +18,8 @@
public class AssignArgumentStatement:Statement
{
- private ArgumentReference argument;
- private Expression expression;
+ private readonly ArgumentReference argument;
+ private readonly Expression expression;
public AssignArgumentStatement(ArgumentReference argument,
Expression expression)
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
==================================================================
File [modified]: AttributeDisassembler.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/AttributesToAvoidReplicating.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/AttributesToAvoidReplicating.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -20,7 +20,7 @@
public static class AttributesToAvoidReplicating
{
- internal static readonly List<Type> attributes = new
List<Type>();
+ private static readonly IList<Type> attributes = new
List<Type>();
static AttributesToAvoidReplicating()
File [modified]: AttributesToAvoidReplicating.cs
Delta lines: +1 -1
===================================================================
--- DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/BaseProxyGenerator.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/BaseProxyGenerator.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -121,7 +121,7 @@
#endregion
- protected void GenerateConstructor(ClassEmitter emitter,
ConstructorInfo baseConstructor, params FieldReference[] fields)
+ private void GenerateConstructor(ClassEmitter emitter,
ConstructorInfo baseConstructor, params FieldReference[] fields)
{
ArgumentReference[] args;
File [modified]: BaseProxyGenerator.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/ClassProxyGenerator.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/ClassProxyGenerator.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -145,7 +145,7 @@
return proxyType;
}
- private ICollection<Type> GetTypeImplementerMapping(Type[]
interfaces, out IEnumerable<ITypeContributor> contributors, INamingScope
namingScope)
+ private IEnumerable<Type> GetTypeImplementerMapping(Type[]
interfaces, out IEnumerable<ITypeContributor> contributors, INamingScope
namingScope)
{
var methodsToSkip = new List<MethodInfo>();
File [modified]: ClassProxyGenerator.cs
Delta lines: +22 -2
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/ArgumentsUtil.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/ArgumentsUtil.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -54,7 +54,7 @@
public static ArgumentReference[]
ConvertToArgumentReference(Type[] args)
{
- ArgumentReference[] arguments = new
ArgumentReference[args.Length];
+ var arguments = new ArgumentReference[args.Length];
for (int i = 0; i < args.Length; ++i)
{
@@ -64,9 +64,18 @@
return arguments;
}
+ public static bool IsAnyByRef(ParameterInfo[] parameters)
+ {
+ for (int i = 0; i < parameters.Length; i++)
+ {
+ if (parameters[i].ParameterType.IsByRef) return
true;
+ }
+ return false;
+ }
+
public static ArgumentReference[]
ConvertToArgumentReference(ParameterInfo[] args)
{
- ArgumentReference[] arguments = new
ArgumentReference[args.Length];
+ var arguments = new ArgumentReference[args.Length];
for (int i = 0; i < args.Length; ++i)
{
@@ -76,6 +85,17 @@
return arguments;
}
+ public static ReferenceExpression[]
ConvertToArgumentReferenceExpression(ParameterInfo[] args)
+ {
+ var arguments = new ReferenceExpression[args.Length];
+
+ for (int i = 0; i < args.Length; ++i)
+ {
+ arguments[i] = new ReferenceExpression(new
ArgumentReference(args[i].ParameterType, i + 1));
+ }
+
+ return arguments;
+ }
public static Expression[]
ConvertArgumentReferenceToExpression(ArgumentReference[] args)
{
File [modified]: InterfaceMethodGenerator.cs
Delta lines: +2 -5
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InvocationTypeGenerator.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InvocationTypeGenerator.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -83,14 +83,11 @@
if (callback != null)
{
- ParameterInfo[] parameters =
methodInfo.GetParameters();
-
- CreateIInvocationInvokeOnTarget(nested,
parameters, targetRef, callback);
+ CreateIInvocationInvokeOnTarget(nested,
methodInfo.GetParameters(), targetRef, callback);
}
else if (method.HasTarget)
{
- ParameterInfo[] parameters =
methodInfo.GetParameters();
- CreateIInvocationInvokeOnTarget(nested,
parameters, targetRef, methodInfo);
+ CreateIInvocationInvokeOnTarget(nested,
methodInfo.GetParameters(), targetRef, methodInfo);
}
else
File [modified]: InvocationTypeGenerator.cs
Delta lines: +304 -0
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/MethodWithCallbackGenerator.cs
(rev 0)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/MethodWithCallbackGenerator.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -0,0 +1,304 @@
+// 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.
+using System;
+using System.Diagnostics;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Xml.Serialization;
+
+using Castle.Core.Interceptor;
+using Castle.DynamicProxy.Generators.Emitters;
+using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
+using Castle.DynamicProxy.Tokens;
+
+namespace Castle.DynamicProxy.Generators
+{
+ using Castle.DynamicProxy.Contributors;
+
+ public class MethodWithCallbackGenerator:MethodGenerator
+ {
+ private readonly MethodToGenerate method;
+ private readonly NestedClassEmitter invocation;
+ private readonly Reference interceptors;
+ private readonly CreateMethodDelegate createMethod;
+
+ public MethodWithCallbackGenerator(MethodToGenerate method,
NestedClassEmitter invocation, Reference interceptors, CreateMethodDelegate
createMethod)
+ {
+ this.method = method;
+ this.invocation = invocation;
+ this.interceptors = interceptors;
+ this.createMethod = createMethod;
+ }
+
+ public override MethodEmitter Generate(ClassEmitter @class,
ProxyGenerationOptions options, INamingScope namingScope)
+ {
+ string name;
+ var atts = ObtainMethodAttributes(out name);
+ var methodEmitter = createMethod(name, atts);
+ var proxiedMethod =
ImplementProxiedMethod(methodEmitter,
+ @class,
+ options,
+ namingScope);
+
+ if (method.Method.DeclaringType.IsInterface)
+ {
+
@class.TypeBuilder.DefineMethodOverride(methodEmitter.MethodBuilder,
method.Method);
+
+ }
+ return proxiedMethod;
+ }
+
+ private MethodEmitter ImplementProxiedMethod(MethodEmitter
emitter, ClassEmitter @class, ProxyGenerationOptions options,INamingScope
namingScope)
+ {
+ var methodInfo = method.Method;
+ emitter.CopyParametersAndReturnTypeFrom(methodInfo,
@class);
+
+ TypeReference[] dereferencedArguments =
IndirectReference.WrapIfByRef(emitter.Arguments);
+
+ Type iinvocation = invocation.TypeBuilder;
+
+ Trace.Assert(methodInfo.IsGenericMethod ==
iinvocation.IsGenericTypeDefinition);
+ bool isGenericInvocationClass = false;
+ Type[] genericMethodArgs = Type.EmptyTypes;
+ if (methodInfo.IsGenericMethod)
+ {
+ // bind generic method arguments to
invocation's type arguments
+ genericMethodArgs =
emitter.MethodBuilder.GetGenericArguments();
+ iinvocation =
iinvocation.MakeGenericType(genericMethodArgs);
+ isGenericInvocationClass = true;
+ }
+
+ Expression methodInfoTokenExp;
+
+ string tokenFieldName;
+ if (methodInfo.IsGenericMethod)
+ {
+ // Not in the cache: generic method
+ MethodInfo genericMethod =
methodInfo.MakeGenericMethod(genericMethodArgs);
+
+ tokenFieldName =
namingScope.GetUniqueName("token_" + methodInfo.Name);
+ methodInfoTokenExp = new
MethodTokenExpression(genericMethod);
+ }
+ else
+ {
+
+ var methodTokenField =
@class.CreateStaticField(namingScope.GetUniqueName("token_" + methodInfo.Name),
+
typeof (MethodInfo));
+
@class.ClassConstructor.CodeBuilder.AddStatement(new
AssignStatement(methodTokenField, new MethodTokenExpression(methodInfo)));
+ tokenFieldName =
methodTokenField.Reference.Name;
+ methodInfoTokenExp =
methodTokenField.ToExpression();
+ }
+
+ LocalReference invocationImplLocal =
emitter.CodeBuilder.DeclareLocal(iinvocation);
+
+ // TODO: Initialize iinvocation instance with ordinary
arguments and in and out arguments
+
+ ConstructorInfo constructor =
invocation.Constructors[0].ConstructorBuilder;
+ if (isGenericInvocationClass)
+ {
+ constructor =
TypeBuilder.GetConstructor(iinvocation, constructor);
+ }
+
+ Expression targetMethod = methodInfoTokenExp;
+ Expression interfaceMethod = NullExpression.Instance;
+
+
+ NewInstanceExpression newInvocImpl;
+
+ // TODO: this is not always true. Should be passed
explicitly as ctor parameter
+ Type targetType = methodInfo.DeclaringType;
+ Debug.Assert(targetType != null, "targetType != null");
+ if (options.Selector == null)
+ {
+ newInvocImpl = //actual contructor call
+ new NewInstanceExpression(constructor,
+
SelfReference.Self.ToExpression(),
+
SelfReference.Self.ToExpression(),
+
interceptors.ToExpression(),
+ // NOTE:
there's no need to cache type token
+ // profiling
showed that it gives no real performance gain
+ new
TypeTokenExpression(targetType),
+ targetMethod,
+
interfaceMethod,
+ new
ReferencesToObjectArrayExpression(dereferencedArguments));
+ }
+ else
+ {
+ // Create the field to store the selected
interceptors for this method if an InterceptorSelector is specified
+ // NOTE: If no interceptors are returned,
should we invoke the base.Method directly? Looks like we should not.
+ var methodInterceptors =
@class.CreateField(string.Format("{0}_interceptors", tokenFieldName),
+
typeof (IInterceptor[]), false);
+
+#if !SILVERLIGHT
+
@class.DefineCustomAttributeFor<XmlIgnoreAttribute>(methodInterceptors);
+#endif
+
+ MethodInvocationExpression selector =
+ new
MethodInvocationExpression(@class.GetField("proxyGenerationOptions"),
+
ProxyGenerationOptionsMethods.GetSelector);
+ selector.VirtualCall = true;
+
+ newInvocImpl = //actual contructor call
+ new NewInstanceExpression(constructor,
+
SelfReference.Self.ToExpression(),
+
SelfReference.Self.ToExpression(),
+
interceptors.ToExpression(),
+ new
TypeTokenExpression(targetType),
+ targetMethod,
+
interfaceMethod,
+ new
ReferencesToObjectArrayExpression(dereferencedArguments),
+ selector,
+ new
AddressOfReferenceExpression(methodInterceptors));
+ }
+
+ emitter.CodeBuilder.AddStatement(new
AssignStatement(invocationImplLocal, newInvocImpl));
+
+ if (methodInfo.ContainsGenericParameters)
+ {
+ EmitLoadGenricMethodArguments(emitter,
methodInfo.MakeGenericMethod(genericMethodArgs), invocationImplLocal);
+ }
+
+ emitter.CodeBuilder.AddStatement(
+ new ExpressionStatement(new
MethodInvocationExpression(invocationImplLocal, InvocationMethods.Proceed)));
+
+ CopyOutAndRefParameters(dereferencedArguments,
invocationImplLocal, methodInfo, emitter);
+
+ if (methodInfo.ReturnType != typeof(void))
+ {
+ // Emit code to return with cast from
ReturnValue
+ MethodInvocationExpression getRetVal =
+ new
MethodInvocationExpression(invocationImplLocal,
InvocationMethods.GetReturnValue);
+
+ emitter.CodeBuilder.AddStatement(
+ new ReturnStatement(new
ConvertExpression(emitter.ReturnType, getRetVal)));
+ }
+ else
+ {
+ emitter.CodeBuilder.AddStatement(new
ReturnStatement());
+ }
+
+ return emitter;
+ }
+
+ private static void CopyOutAndRefParameters(TypeReference[]
dereferencedArguments, Reference invocationImplLocal, MethodInfo method,
MethodEmitter methodEmitter)
+ {
+ var parameters = method.GetParameters();
+ if (!ArgumentsUtil.IsAnyByRef(parameters))
+ return; //saving the need to create locals if
there is no need
+ LocalReference invocationArgs =
methodEmitter.CodeBuilder.DeclareLocal(typeof(object[]));
+ methodEmitter.CodeBuilder.AddStatement(
+ new AssignStatement(invocationArgs,
+ new
MethodInvocationExpression(invocationImplLocal, InvocationMethods.GetArguments)
+ )
+ );
+ for (int i = 0; i < parameters.Length; i++)
+ {
+ if (parameters[i].ParameterType.IsByRef)
+ {
+ methodEmitter.CodeBuilder.AddStatement(
+ new
AssignStatement(dereferencedArguments[i],
+ new
ConvertExpression(dereferencedArguments[i].Type,
+
new LoadRefArrayElementExpression(i, invocationArgs)
+ )
+ ));
+ }
+ }
+ }
+
+
+
+ private void EmitLoadGenricMethodArguments(MethodEmitter
methodEmitter, MethodInfo method, Reference invocationImplLocal)
+ {
+#if SILVERLIGHT
+ Type[] genericParameters =
+
Castle.Core.Extensions.SilverlightExtensions.FindAll(method.GetGenericArguments(),
delegate(Type t) { return t.IsGenericParameter; });
+#else
+ Type[] genericParameters =
Array.FindAll(method.GetGenericArguments(), t => t.IsGenericParameter);
+#endif
+ LocalReference genericParamsArrayLocal =
methodEmitter.CodeBuilder.DeclareLocal(typeof(Type[]));
+ methodEmitter.CodeBuilder.AddStatement(
+ new AssignStatement(genericParamsArrayLocal,
new NewArrayExpression(genericParameters.Length, typeof(Type))));
+
+ for (int i = 0; i < genericParameters.Length; ++i)
+ {
+ methodEmitter.CodeBuilder.AddStatement(
+ new
AssignArrayStatement(genericParamsArrayLocal, i, new
TypeTokenExpression(genericParameters[i])));
+ }
+ methodEmitter.CodeBuilder.AddStatement(new
ExpressionStatement(
+ new
MethodInvocationExpression(invocationImplLocal,
InvocationMethods.SetGenericMethodArguments,
+
new ReferenceExpression(
+
genericParamsArrayLocal))));
+ }
+
+ private bool IsInterfaceMethodForExplicitImplementation()
+ {
+ return method.Method.DeclaringType.IsInterface &&
+ method.MethodOnTarget.IsFinal;
+ }
+
+ private MethodAttributes ObtainMethodAttributes(out string name)
+ {
+ var methodInfo = method.Method;
+ MethodAttributes attributes = MethodAttributes.Virtual;
+ if (IsInterfaceMethodForExplicitImplementation())
+ {
+ name = methodInfo.DeclaringType.Name + "." +
methodInfo.Name;
+ attributes |= MethodAttributes.Private |
+ MethodAttributes.HideBySig |
+ MethodAttributes.NewSlot |
+ MethodAttributes.Final;
+ }
+ else
+ {
+ if (methodInfo.IsFinal)
+ {
+ attributes |= MethodAttributes.NewSlot;
+ }
+
+ if (methodInfo.IsPublic)
+ {
+ attributes |= MethodAttributes.Public;
+ }
+
+ if (methodInfo.IsHideBySig)
+ {
+ attributes |=
MethodAttributes.HideBySig;
+ }
+ if (InternalsHelper.IsInternal(methodInfo) &&
InternalsHelper.IsInternalToDynamicProxy(methodInfo.DeclaringType.Assembly))
+ {
+ attributes |= MethodAttributes.Assembly;
+ }
+ if (methodInfo.IsFamilyAndAssembly)
+ {
+ attributes |=
MethodAttributes.FamANDAssem;
+ }
+ else if (methodInfo.IsFamilyOrAssembly)
+ {
+ attributes |=
MethodAttributes.FamORAssem;
+ }
+ else if (methodInfo.IsFamily)
+ {
+ attributes |= MethodAttributes.Family;
+ }
+ name = methodInfo.Name;
+ }
+
+ if (method.Standalone == false)
+ {
+ attributes |= MethodAttributes.SpecialName;
+ }
+ return attributes;
+ }
+ }
+}
File [added]: MethodWithCallbackGenerator.cs
Delta lines: +2 -2
===================================================================
--- DynamicProxy/trunk/src/Castle.DynamicProxy/ModuleScope.cs 2009-11-10
15:11:32 UTC (rev 6309)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/ModuleScope.cs 2009-11-10
17:59:08 UTC (rev 6310)
@@ -44,8 +44,8 @@
/// </summary>
public static readonly String DEFAULT_ASSEMBLY_NAME =
"DynamicProxyGenAssembly2";
- private ModuleBuilder moduleBuilderWithStrongName = null;
- private ModuleBuilder moduleBuilder = null;
+ private ModuleBuilder moduleBuilderWithStrongName;
+ private ModuleBuilder moduleBuilder;
// The names to use for the generated assemblies and the paths
(including the names) of their manifest modules
Directory:
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/
=====================================================================================
File [modified]: AssignArgumentStatement.cs
Delta lines: +3 -3
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/AssignArrayStatement.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/AssignArrayStatement.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -18,9 +18,9 @@
public class AssignArrayStatement : Statement
{
- private Reference targetArray;
- private int targetPosition;
- private Expression value;
+ private readonly Reference targetArray;
+ private readonly int targetPosition;
+ private readonly Expression value;
public AssignArrayStatement(Reference targetArray, int
targetPosition, Expression value)
File [modified]: AssignArrayStatement.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/ExpressionStatement.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/ExpressionStatement.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -18,7 +18,7 @@
public class ExpressionStatement : Statement
{
- private Expression expression;
+ private readonly Expression expression;
public ExpressionStatement(Expression expression)
File [modified]: ExpressionStatement.cs
Delta lines: +2 -2
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/NewArrayExpression.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/NewArrayExpression.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -22,8 +22,8 @@
/// </summary>
public class NewArrayExpression : Expression
{
- private int size;
- private Type arrayType;
+ private readonly int size;
+ private readonly Type arrayType;
public NewArrayExpression(int size, Type arrayType)
File [modified]: NewArrayExpression.cs
Delta lines: +5 -5
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/NewInstanceExpression.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/SimpleAST/NewInstanceExpression.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -20,9 +20,9 @@
public class NewInstanceExpression : Expression
{
- private Type type;
- private Type[] constructor_args;
- private Expression[] arguments;
+ private readonly Type type;
+ private readonly Type[] constructorArgs;
+ private readonly Expression[] arguments;
private ConstructorInfo constructor;
public NewInstanceExpression(ConstructorInfo constructor,
params Expression[] args)
@@ -34,7 +34,7 @@
public NewInstanceExpression(Type target, Type[]
constructor_args, params Expression[] args)
{
type = target;
- this.constructor_args = constructor_args;
+ this.constructorArgs = constructor_args;
arguments = args;
}
@@ -47,7 +47,7 @@
if (constructor == null)
{
- constructor =
type.GetConstructor(constructor_args);
+ constructor =
type.GetConstructor(constructorArgs);
}
File [modified]: NewInstanceExpression.cs
Delta lines: +6 -11
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceMethodGenerator.cs
2009-11-10 15:11:32 UTC (rev 6309)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceMethodGenerator.cs
2009-11-10 17:59:08 UTC (rev 6310)
@@ -185,10 +185,9 @@
@class.DefineCustomAttributeFor<XmlIgnoreAttribute>(methodInterceptors);
#endif
- MethodInvocationExpression selector =
- new
MethodInvocationExpression(@class.GetField("proxyGenerationOptions"),
-
ProxyGenerationOptionsMethods.GetSelector);
- selector.VirtualCall = true;
+ var selector = new MethodInvocationExpression(
+
@class.GetField("proxyGenerationOptions"),
+
ProxyGenerationOptionsMethods.GetSelector) { VirtualCall = true };
newInvocImpl = //actual contructor call
new NewInstanceExpression(constructor,
@@ -233,15 +232,11 @@
private static void CopyOutAndRefParameters(TypeReference[]
dereferencedArguments, LocalReference invocationImplLocal, MethodInfo method,
MethodEmitter methodEmitter)
{
- ParameterInfo[] parameters = method.GetParameters();
- bool hasByRefParam = false;
- for (int i = 0; i < parameters.Length; i++)
+ var parameters = method.GetParameters();
+ if(!ArgumentsUtil.IsAnyByRef(parameters))
{
- if (parameters[i].ParameterType.IsByRef)
- hasByRefParam = true;
- }
- if (!hasByRefParam)
return; //saving the need to create locals if
there is no need
+ }
LocalReference invocationArgs =
methodEmitter.CodeBuilder.DeclareLocal(typeof(object[]));
methodEmitter.CodeBuilder.AddStatement(
--
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=.