public static async Task <FactorySyntax> FromDeclarationAsync(InterfaceDeclarationSyntax syntax, Document document, CancellationToken ct) { async Task <INamedTypeSymbol> GetSymbol() { var ns = syntax.Parent is NamespaceDeclarationSyntax nsds ? (nsds.Name is QualifiedNameSyntax qns ? qns.ToString() : throw new Exception()) : throw new Exception(); var symbols = await SymbolFinder.FindSourceDeclarationsAsync( document.Project, syntax.Identifier.ValueText, false, ct); var namedTypeSymbol = symbols.OfType <INamedTypeSymbol>() .First(x => x.GetFullNameSpace() == ns); return(namedTypeSymbol); } var symbol = await GetSymbol(); var resolvers = ResolverSyntax.FromParent(symbol); var captures = CaptureSyntax.FromFactory(symbol); return(new FactorySyntax(symbol, resolvers.Item1, resolvers.Item2, captures)); }
public static CaptureSyntax[] FromFactory(INamedTypeSymbol factory) { IEnumerable <CaptureSyntax> GetCaptures() { var inInterfaces = factory.AllInterfaces .SelectMany(x => x.GetMembers()); var properties = factory.GetMembers() .Concat(inInterfaces) .OfType <IPropertySymbol>(); foreach (var property in properties) { if (!property.IsReadOnly) { continue; } if (!property.Type.HasAttribute(nameof(FactoryAttribute))) { continue; } if (property.Type is INamedTypeSymbol namedType) { var resolvers = ResolverSyntax.FromParent(namedType); yield return(new CaptureSyntax(property.Name, TypeName.FromSymbol(namedType), resolvers.Item1, resolvers.Item2)); } } } return(GetCaptures().ToArray()); }