Skip to content

Commit

Permalink
fix: adding error message if attribute is used on static method
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 31, 2024
1 parent 7a0b3f3 commit dc66a54
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Assets/Mirage/Weaver/Processors/AttributeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void CheckAttribute<TAttribute>(MethodDefinition md, FoundType foundType
}
}

private bool TryGetAttribte<TAttribute>(MethodDefinition md, FoundType foundType, out CustomAttribute attribute)
private bool TryGetAttribute<TAttribute>(MethodDefinition md, FoundType foundType, out CustomAttribute attribute)
{
attribute = md.GetCustomAttribute<TAttribute>();
if (attribute == null)
Expand All @@ -140,14 +140,20 @@ private bool TryGetAttribte<TAttribute>(MethodDefinition md, FoundType foundType
return false;
}

if (md.IsStatic)
{
logger.Error($"{attribute.AttributeType.Name} will not work on static method.", md);
return false;
}

// dont need to set modified for errors, so we set it here when we start doing ILProcessing
modified = true;
return true;
}

private void InjectGuard<TAttribute>(MethodDefinition md, FoundType foundType, MethodReference predicate, string format)
{
if (!TryGetAttribte<TAttribute>(md, foundType, out var attribute))
if (!TryGetAttribute<TAttribute>(md, foundType, out var attribute))
return;

var throwError = attribute.GetField("error", true);
Expand Down Expand Up @@ -176,7 +182,7 @@ private void InjectGuard<TAttribute>(MethodDefinition md, FoundType foundType, M

private void InjectNetworkMethodGuard(MethodDefinition md, FoundType foundType)
{
if (!TryGetAttribte<NetworkMethodAttribute>(md, foundType, out var attribute))
if (!TryGetAttribute<NetworkMethodAttribute>(md, foundType, out var attribute))
return;

// Get the required flags from the attribute constructor argument
Expand Down

0 comments on commit dc66a54

Please sign in to comment.