internal static bool IsAssignableFrom()

in sdk/Sdk.Analyzers/Extensions/TypeSymbolExtensions.cs [16:42]


        internal static bool IsAssignableFrom(this ITypeSymbol targetType, ITypeSymbol sourceType, bool exactMatch = false)
        {
            if (targetType != null)
            {
                while (sourceType != null)
                {
                    if (sourceType.Equals(targetType, SymbolEqualityComparer.Default))
                    {
                        return true;
                    }

                    if (exactMatch)
                    {
                        return false;
                    }

                    if (targetType.TypeKind == TypeKind.Interface)
                    {
                        return sourceType.AllInterfaces.Any(i => i.Equals(targetType, SymbolEqualityComparer.Default));
                    }

                    sourceType = sourceType.BaseType;
                }
            }

            return false;
        }