JsonRpc/CodeGenerator/AttributeChecker.cs

37 lines
1.2 KiB
C#
Raw Permalink Normal View History

2025-10-14 21:05:08 +08:00
using Mono.Cecil;
namespace CodeGenerator
{
public static class AttributeChecker
{
public static CustomAttribute? GetTargetttribute(this ICustomAttributeProvider definition)
{
var customAttributes = definition.CustomAttributes;
return customAttributes.FirstOrDefault(_ => _.AttributeType.Name == nameof(JsonRPCAttribute));
}
public static bool ContainsTargetAttribute(this ICustomAttributeProvider definition) =>
GetTargetttribute(definition) != null;
public static bool IsCompilerGenerated(this ICustomAttributeProvider definition)
{
var customAttributes = definition.CustomAttributes;
return customAttributes.Any(_ => _.AttributeType.Name == "CompilerGeneratedAttribute");
}
public static void RemoveTargetAttribute(this ICustomAttributeProvider definition)
{
var customAttributes = definition.CustomAttributes;
var targetAttribute = customAttributes.FirstOrDefault(_ => _.AttributeType.Name == nameof(JsonRPCAttribute));
if (targetAttribute != null)
{
customAttributes.Remove(targetAttribute);
}
}
}
}