mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 06:42:25 +02:00
Revert "Revert "Add analyzer & fixer to detect when proxy methods are not use…"
This reverts commit 1af32c3129.
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
namespace Robust.Roslyn.Shared;
|
|
|
|
#nullable enable
|
|
|
|
public static class AttributeHelper
|
|
{
|
|
public static bool HasAttribute(ISymbol symbol, string attributeMetadataName, [NotNullWhen(true)] out AttributeData? matchedAttribute)
|
|
{
|
|
foreach (var attribute in symbol.GetAttributes())
|
|
{
|
|
if (attribute.AttributeClass == null)
|
|
continue;
|
|
|
|
if (TypeSymbolHelper.ShittyTypeMatch(attribute.AttributeClass, attributeMetadataName))
|
|
{
|
|
matchedAttribute = attribute;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
matchedAttribute = null;
|
|
return false;
|
|
}
|
|
|
|
public static bool GetNamedArgumentBool(AttributeData data, string name, bool defaultValue)
|
|
{
|
|
foreach (var kv in data.NamedArguments)
|
|
{
|
|
if (kv.Key != name)
|
|
continue;
|
|
|
|
if (kv.Value.Kind != TypedConstantKind.Primitive)
|
|
continue;
|
|
|
|
if (kv.Value.Value is not bool value)
|
|
continue;
|
|
|
|
return value;
|
|
}
|
|
|
|
return defaultValue;
|
|
}
|
|
|
|
public static bool HasAttribute(
|
|
ISymbol symbol,
|
|
ITypeSymbol attribute,
|
|
[NotNullWhen(true)] out AttributeData? matchedAttribute)
|
|
{
|
|
matchedAttribute = null;
|
|
foreach (var typeAttribute in symbol.GetAttributes())
|
|
{
|
|
if (SymbolEqualityComparer.Default.Equals(typeAttribute.AttributeClass, attribute))
|
|
{
|
|
matchedAttribute = typeAttribute;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|