Skip to content

Commit

Permalink
skip faster aspect method invocation for open generic types
Browse files Browse the repository at this point in the history
  • Loading branch information
dd committed Oct 18, 2021
1 parent a801966 commit 7c1518f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public NamedInstructionBlockChain CreateMethodExecutionArgsInstance(
var methodBaseVariable = _creator.CreateVariable(methodBaseTypeRef);
InstructionBlock callGetCurrentMethodBlock;
var variablePersistable = new VariablePersistable(methodBaseVariable);
if (methodInfoCompileTimeWeaver?.IsEnabled != true)
if (methodInfoCompileTimeWeaver?.IsEnabled != true || !methodInfoCompileTimeWeaver.CanWeave(method))
{
// fallback: slow GetCurrentMethod
var methodBaseGetCurrentMethod = _referenceFinder.GetMethodReference(methodBaseTypeRef,
Expand Down
22 changes: 22 additions & 0 deletions src/MethodBoundaryAspect.Fody/MethodInfoCompileTimeWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ public void Finish()
if (_fieldsCache.Any())
CreateStaticCtor();
}

public bool CanWeave(MethodDefinition method)
{
// no support for open generic types
if (IsOpenType(method))
return false;

var parentType = method.DeclaringType;
while (parentType != null)
{
if (IsOpenType(parentType))
return false;
parentType = parentType.DeclaringType;
}

return true;
}

private static bool IsOpenType(IGenericParameterProvider method)
{
return method.GenericParameters.Any(x => x.IsGenericParameter);
}

private string CreateIdentifier(MemberReference method)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MethodBoundaryAspect.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ModuleWeaver()
InitLogging();
}

public bool DisableCompileTimeMethodInfos { get; set; } = true;
public bool DisableCompileTimeMethodInfos { get; set; }

public int TotalWeavedTypes { get; private set; }
public int TotalWeavedMethods { get; private set; }
Expand Down

0 comments on commit 7c1518f

Please sign in to comment.