private static IEnumerable<TypeSyntax> GetAllReferencedTypes(TypeSyntax type, SyntaxNodeAnalysisContext context)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
// The "all referenced types" set will be the current type and any generic type parameters that it has (and any generic type parameters that
// they might have)..
yield return type;
// .. so, if this type doesn't have any type parameters then we're done here..
// If this isn't
var genericTypeIfApplicable = type as GenericNameSyntax;
if (genericTypeIfApplicable == null)
yield break;
// .. alternatively, if the type has the Bridge [IgnoreGeneric] attribute on it then we don't need to worry about the type parameters since
// there won't be references to them at runtime
var typeSymbolInfo = context.SemanticModel.GetSymbolInfo(type);
if ((typeSymbolInfo.Symbol != null) && typeSymbolInfo.Symbol.GetAttributes().Any(attribute => IsBridgeClass(attribute.AttributeClass, "IgnoreGenericAttribute")))
yield break;
foreach (var typeParameter in genericTypeIfApplicable.TypeArgumentList.Arguments)
{
foreach (var typeRelatedToTypeParameter in GetAllReferencedTypes(typeParameter, context))
yield return typeRelatedToTypeParameter;
}
}