internal TypePartialMetaInfo(NamedTypeMetaInfo source, ITypeSymbolProvider analysis, SyntaxModelPair syntaxPair, Func <ISymbol, bool>?memberPredicate, CancellationToken ct) { var attributeListing = syntaxPair.Syntax.GetAttributes(source.Symbol); _attributeLookup = attributeListing.Locations; Full = source; Location = syntaxPair.Syntax.GetLocation(); Attributes = attributeListing.Lists; Members = GetUnderlyingMembers(); IReadOnlyList <MemberMetaInfo> GetUnderlyingMembers() { var members = new List <MemberMetaInfo>(); foreach (var member in syntaxPair.Syntax.Members) { var symbol = syntaxPair.Model.GetDeclaredSymbol(member, ct); // Filter out null symbols and symbols that are not enlisted for interest if (symbol is null || !(memberPredicate?.Invoke(symbol) ?? true)) { continue; } // We don't support partial method, so we ignore symbols that are not impl. // In future versions when we have use cases that can benefit from partial, then we should consider adding Attributes to the DefinitionPart // Adding to the commented "DeclaringAttribute" part if (symbol is IMethodSymbol method && method.PartialImplementationPart != null && method.PartialDefinitionPart is null && member.Modifiers.Any(SyntaxKind.PartialKeyword)) { continue; } members.Add(new MemberMetaInfo(this, member, analysis, symbol)); } return(members); } }
private NamedTypeMetaInfo(NamedTypeMetaInfo source, INamedTypeSymbol newSymbol) { _analysis = source._analysis; Symbol = newSymbol; IsPartial = source.IsPartial; FirstLocation = source.FirstLocation; Attributes = source.Attributes; Declarations = source.Declarations.Select(x => new TypePartialMetaInfo(this, x, newSymbol)).ToList(); Members = Declarations.SelectMany(x => x.Members).ToList(); GenericDefinition = source; }
internal TypePartialMetaInfo(NamedTypeMetaInfo parent, TypePartialMetaInfo source, INamedTypeSymbol newSymbol) { if (!newSymbol.ConstructedFrom.Equals(source.Full.Symbol, SymbolEqualityComparer.Default)) { throw new ArgumentException($"New symbol '{newSymbol}' is not a construction of the generic definition from the source symbol '{source.Full.Symbol}'", nameof(newSymbol)); } var memberLookup = newSymbol.GetMembers().ToDictionary(x => x.OriginalDefinition, x => x, SymbolEqualityComparer.Default); _attributeLookup = source._attributeLookup; Full = parent; Location = source.Location; Attributes = source.Attributes; Members = source.Members.Select(x => new MemberMetaInfo(this, x, memberLookup[x.Symbol])).ToList(); }
public bool Equals(NamedTypeMetaInfo other) => other.Symbol.Equals(Symbol, SymbolEqualityComparer.Default);