Skip to content

Commit

Permalink
fixed #85
Browse files Browse the repository at this point in the history
  • Loading branch information
pamidur committed Feb 11, 2019
1 parent d3227f4 commit 53584c5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ private MethodDefinition DuplicateMethodDefinition(MethodDefinition origin)
origin.Attributes,
origin.ReturnType);

foreach (var gparam in origin.GenericParameters)
method.GenericParameters.Add(new GenericParameter(gparam.Name, method));
foreach (var gparam in origin.GenericParameters)
method.GenericParameters.Add(gparam.Clone(method,_ts));

if (origin.ReturnType.IsGenericParameter && ((GenericParameter)origin.ReturnType).Owner == origin)
method.ReturnType = method.GenericParameters[origin.GenericParameters.IndexOf((GenericParameter)origin.ReturnType)];
Expand Down
2 changes: 1 addition & 1 deletion src/AspectInjector.Core.Mixin/MixinWeaveProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected MethodDefinition GetOrCreateMethodProxy(MethodReference ifaceMethod)
_target.Methods.Add(proxy);

foreach (var gp in ifaceMethod.GenericParameters)
proxy.GenericParameters.Add(new GenericParameter(gp.Name, proxy));
proxy.GenericParameters.Add(gp.Clone(proxy, _ts));

proxy.GetEditor().Mark(_ts.DebuggerHiddenAttribute);
proxy.ReturnType = _ts.Import(ifaceMethod.ResolveIfGeneric(ifaceMethod.ReturnType));
Expand Down
31 changes: 31 additions & 0 deletions src/AspectInjector.Core/Extensions/ClonningExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using AspectInjector.Core.Fluent;
using Mono.Cecil;

namespace AspectInjector.Core.Extensions
{
public static class ClonningExtensions
{
public static GenericParameter Clone(this GenericParameter gparam, IGenericParameterProvider target, ExtendedTypeSystem ts)
{
var ngp = new GenericParameter(gparam.Name, target)
{
HasDefaultConstructorConstraint = gparam.HasDefaultConstructorConstraint,
HasReferenceTypeConstraint = gparam.HasReferenceTypeConstraint,
HasNotNullableValueTypeConstraint = gparam.HasNotNullableValueTypeConstraint,
IsNonVariant = gparam.IsNonVariant,
IsContravariant = gparam.IsContravariant,
IsCovariant = gparam.IsCovariant,
//Namespace = gparam.Namespace,
IsValueType = gparam.IsValueType
};

foreach (var gc in gparam.Constraints)
ngp.Constraints.Add(ts.Import(gc));

foreach (var subgp in gparam.GenericParameters)
ngp.GenericParameters.Add(subgp.Clone(target,ts));

return ngp;
}
}
}
13 changes: 10 additions & 3 deletions tests/AspectInjector.Tests.Runtime/Advices/AroundTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using Xunit;

namespace AspectInjector.Tests.Advices
Expand All @@ -23,7 +25,9 @@ public void Advices_InjectAroundMethod_StructResult()
var dt = DateTime.Now;
var arr = new[] {1,2,3 };

a.Do1<string>(new object(), 1, str, ref str, dt, ref dt,str,ref str, arr, ref arr, ref ref1, out out1, ref ref2, out out2, false, false);
var sb = new StringBuilder();

a.Do1<StringBuilder>(new object(), 1, str, ref str, dt, ref dt, sb, ref sb, arr, ref arr, ref ref1, out out1, ref ref2, out out2, false, false);

Assert.True(Checker.Passed);
}
Expand Down Expand Up @@ -55,6 +59,8 @@ public void Advices_InjectAroundMethod_ModifyArguments()
Assert.True(Checker.Passed);
}



internal class AroundTests_Target
{
[AroundTests_Aspect1]
Expand All @@ -71,7 +77,8 @@ public object Do2(object data, int value, ref object testRef, out object testOut

[AroundTests_Aspect1]
[AroundTests_Aspect2] //fire first
public int Do1<T>(object data, int value, string str, ref string rstr, DateTime dt, ref DateTime rdt, T g, ref T rg, int[] arr, ref int[] rarr, ref object testRef, out object testOut, ref int testRefValue, out int testOutValue, bool passed, bool passed2)
public T Do1<T>(object data, int value, string str, ref string rstr, DateTime dt, ref DateTime rdt, T g, ref T rg, int[] arr, ref int[] rarr, ref object testRef, out object testOut, ref int testRefValue, out int testOutValue, bool passed, bool passed2)
where T : ISerializable
{
var test = new object[] { dt, rdt,arr,rarr,g,rg };

Expand All @@ -87,7 +94,7 @@ public int Do1<T>(object data, int value, string str, ref string rstr, DateTime
testOut = new object();
testOutValue = 1;

return 1;
return g;
}

[AroundTests_Aspect1]
Expand Down

0 comments on commit 53584c5

Please sign in to comment.