Пример #1
0
        public static bool EqualsOrDerivedFrom(this ITypeSymbol typeSymbol, ISymbol symbol)
        {
            if (typeSymbol == null)
            {
                throw new ArgumentNullException(nameof(typeSymbol));
            }

            return(typeSymbol.Equals(symbol) ||
                   typeSymbol.BaseTypes().Any(f => f.Equals(symbol)));
        }
Пример #2
0
        public static bool InheritsFrom(this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces = false)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (type.BaseTypes().Any(f => f.Equals(baseType)))
            {
                return(true);
            }
            else if (includeInterfaces)
            {
                return(type.AllInterfaces.Any(f => f.Equals(baseType)));
            }
            else
            {
                return(false);
            }
        }