2025-08-16 13:13:34 +04:00
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
|
2025-08-19 04:33:02 +04:00
|
|
|
namespace Telegrator.RoslynGenerators.RoslynExtensions;
|
2025-08-16 13:13:34 +04:00
|
|
|
|
|
|
|
|
public static class SymbolsExtensions
|
|
|
|
|
{
|
|
|
|
|
public static bool IsAssignableFrom(this ITypeSymbol symbol, string className)
|
|
|
|
|
{
|
|
|
|
|
if (symbol.BaseType == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (symbol.BaseType.Name == className)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return symbol.BaseType.IsAssignableFrom(className);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ITypeSymbol? Cast(this ITypeSymbol symbol, string className)
|
|
|
|
|
{
|
|
|
|
|
if (symbol.BaseType == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if (symbol.BaseType.Name == className)
|
|
|
|
|
return symbol.BaseType;
|
|
|
|
|
|
|
|
|
|
return symbol.BaseType.Cast(className);
|
|
|
|
|
}
|
|
|
|
|
}
|