Skip to content

Commit 7c1518f

Browse files
author
dd
committed
skip faster aspect method invocation for open generic types
1 parent a801966 commit 7c1518f

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/MethodBoundaryAspect.Fody/InstructionBlockChainCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public NamedInstructionBlockChain CreateMethodExecutionArgsInstance(
144144
var methodBaseVariable = _creator.CreateVariable(methodBaseTypeRef);
145145
InstructionBlock callGetCurrentMethodBlock;
146146
var variablePersistable = new VariablePersistable(methodBaseVariable);
147-
if (methodInfoCompileTimeWeaver?.IsEnabled != true)
147+
if (methodInfoCompileTimeWeaver?.IsEnabled != true || !methodInfoCompileTimeWeaver.CanWeave(method))
148148
{
149149
// fallback: slow GetCurrentMethod
150150
var methodBaseGetCurrentMethod = _referenceFinder.GetMethodReference(methodBaseTypeRef,

src/MethodBoundaryAspect.Fody/MethodInfoCompileTimeWeaver.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ public void Finish()
7777
if (_fieldsCache.Any())
7878
CreateStaticCtor();
7979
}
80+
81+
public bool CanWeave(MethodDefinition method)
82+
{
83+
// no support for open generic types
84+
if (IsOpenType(method))
85+
return false;
86+
87+
var parentType = method.DeclaringType;
88+
while (parentType != null)
89+
{
90+
if (IsOpenType(parentType))
91+
return false;
92+
parentType = parentType.DeclaringType;
93+
}
94+
95+
return true;
96+
}
97+
98+
private static bool IsOpenType(IGenericParameterProvider method)
99+
{
100+
return method.GenericParameters.Any(x => x.IsGenericParameter);
101+
}
80102

81103
private string CreateIdentifier(MemberReference method)
82104
{

src/MethodBoundaryAspect.Fody/ModuleWeaver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ModuleWeaver()
4040
InitLogging();
4141
}
4242

43-
public bool DisableCompileTimeMethodInfos { get; set; } = true;
43+
public bool DisableCompileTimeMethodInfos { get; set; }
4444

4545
public int TotalWeavedTypes { get; private set; }
4646
public int TotalWeavedMethods { get; private set; }

0 commit comments

Comments
 (0)