mirror of
https://github.com/StarBeat/JsonRpc.git
synced 2026-03-08 03:55:29 +08:00
37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|