16440bcf43
* Moved AddHandler<T> and AddHandler(Type) methods from IHandlersCollection to extension methods * Added public constructor to IHost types form extensibility * Code cleanup
29 lines
712 B
C#
29 lines
712 B
C#
using Microsoft.CodeAnalysis;
|
|
|
|
namespace Telegrator.RoslynGenerators.RoslynExtensions;
|
|
|
|
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);
|
|
}
|
|
}
|