mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
* Add analyzers to detect some prototype misuse Detects people marking prototype as NetSerializable. Detects people creating new prototype instances themselves. * Update Robust.Analyzers/PrototypeNetSerializableAnalyzer.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using Microsoft.CodeAnalysis;
|
|
|
|
namespace Robust.Roslyn.Shared;
|
|
|
|
#nullable enable
|
|
|
|
public static class TypeSymbolHelper
|
|
{
|
|
public static bool ShittyTypeMatch(ITypeSymbol type, string attributeMetadataName)
|
|
{
|
|
// Doing it like this only allocates when the type actually matches, which is good enough for me right now.
|
|
if (!attributeMetadataName.EndsWith(type.Name))
|
|
return false;
|
|
|
|
return type.ToDisplayString() == attributeMetadataName;
|
|
}
|
|
|
|
public static bool ImplementsInterface(ITypeSymbol type, string interfaceTypeName)
|
|
{
|
|
foreach (var interfaceType in type.AllInterfaces)
|
|
{
|
|
if (ShittyTypeMatch(interfaceType, interfaceTypeName))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static bool ImplementsInterface(ITypeSymbol type, INamedTypeSymbol interfaceType)
|
|
{
|
|
foreach (var @interface in type.AllInterfaces)
|
|
{
|
|
if (SymbolEqualityComparer.Default.Equals(@interface, interfaceType))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|