internal static NamespaceOrTypeSymbol?EnsureCSharpSymbolOrNull( this INamespaceOrTypeSymbol?symbol, string paramName ) { return((NamespaceOrTypeSymbol?)EnsureCSharpSymbolOrNull((ISymbol?)symbol, paramName)); }
/// <summary> /// Gets the available named namespace and type symbols in the context of the specified location and optional container. /// Only members that are accessible and visible from the given location are returned. /// </summary> /// <param name="position">The character position for determining the enclosing declaration scope and /// accessibility.</param> /// <param name="container">The container to search for symbols within. If null then the enclosing declaration /// scope around position is used.</param> /// <param name="name">The name of the symbol to find. If null is specified then symbols /// with any names are returned.</param> /// <returns>A list of symbols that were found. If no symbols were found, an empty list is returned.</returns> /// <remarks> /// The "position" is used to determine what variables are visible and accessible. Even if "container" is /// specified, the "position" location is significant for determining which members of "containing" are /// accessible. /// /// Does not return INamespaceOrTypeSymbol, because there could be aliases. /// </remarks> public ImmutableArray <ISymbol> LookupNamespacesAndTypes( int position, INamespaceOrTypeSymbol?container = null, string?name = null) { return(LookupNamespacesAndTypesCore(position, container, name)); }
private SymbolResult(INamespaceOrTypeSymbol symbol, int weight, INamespaceOrTypeSymbol?originalSymbol) { Symbol = symbol; Weight = weight; NameParts = INamespaceOrTypeSymbolExtensions.GetNameParts(symbol); OriginalSymbol = originalSymbol; }
private static string GetFullReflectionName(INamedTypeSymbol?containingType) { var containingTypeStack = new Stack <string>(); var containingNamespaceStack = new Stack <string>(); for (INamespaceOrTypeSymbol?symbol = containingType; symbol is not null and not INamespaceSymbol { IsGlobalNamespace: true }; symbol = (INamespaceOrTypeSymbol?)symbol.ContainingType ?? symbol.ContainingNamespace) { if (symbol.ContainingType is not null) { containingTypeStack.Push(symbol.MetadataName); } else { containingNamespaceStack.Push(symbol.MetadataName); } } var result = string.Join(".", containingNamespaceStack); if (containingTypeStack.Any()) { result += "+" + string.Join("+", containingTypeStack); } return(result); } }
/// <summary> /// Gets the available named symbols in the context of the specified location and optional container. Only /// symbols that are accessible and visible from the given location are returned. /// </summary> /// <param name="position">The character position for determining the enclosing declaration scope and /// accessibility.</param> /// <param name="container">The container to search for symbols within. If null then the enclosing declaration /// scope around position is used.</param> /// <param name="name">The name of the symbol to find. If null is specified then symbols /// with any names are returned.</param> /// <param name="includeReducedExtensionMethods">Consider (reduced) extension methods.</param> /// <returns>A list of symbols that were found. If no symbols were found, an empty list is returned.</returns> /// <remarks> /// The "position" is used to determine what variables are visible and accessible. Even if "container" is /// specified, the "position" location is significant for determining which members of "containing" are /// accessible. /// /// Labels are not considered (see <see cref="LookupLabels"/>). /// /// Non-reduced extension methods are considered regardless of the value of <paramref name="includeReducedExtensionMethods"/>. /// </remarks> public ImmutableArray <ISymbol> LookupSymbols( int position, INamespaceOrTypeSymbol?container = null, string?name = null, bool includeReducedExtensionMethods = false) { return(LookupSymbolsCore(position, container, name, includeReducedExtensionMethods)); }
private static void GetNameParts(INamespaceOrTypeSymbol?namespaceOrTypeSymbol, List <string> result) { if (namespaceOrTypeSymbol == null || (namespaceOrTypeSymbol.IsNamespace && ((INamespaceSymbol)namespaceOrTypeSymbol).IsGlobalNamespace)) { return; } GetNameParts(namespaceOrTypeSymbol.ContainingNamespace, result); result.Add(namespaceOrTypeSymbol.Name); }
private static AttributeData?TypeToAttribute(INamespaceOrTypeSymbol?typeSymbol, string name) { if (typeSymbol is null) { return(null); } var attributes = typeSymbol.GetAttributes() .Where(x => x.AttributeClass?.ToDisplayString() == name) .ToArray(); return(attributes.Length == 0 ? null : attributes.ExclusiveOrDefault()); }
public static string?GetFullName(this INamespaceOrTypeSymbol?type) { if (type is IArrayTypeSymbol arrayType) { return($"{arrayType.ElementType.GetFullName()}[]"); } if (type is ITypeSymbol ts && ts.IsNullable(out var t)) { return($"System.Nullable`1[{t.GetFullName()}]"); } var name = type?.ToDisplayString(); return(_fullNamesMaping.UnoGetValueOrDefault(name !, name)); }
/// <summary> /// Returns true if <see paramref="type" /> has the same name as <see paramref="typename" /> /// </summary> internal static bool HasName(this INamedTypeSymbol type, string typeName) { var roSpan = typeName.AsSpan(); INamespaceOrTypeSymbol?currentType = type; while (roSpan.Length > 0) { var dot = roSpan.LastIndexOf('.'); var currentName = dot < 0 ? roSpan : roSpan.Slice(dot + 1); if (currentType is null || !currentName.Equals(currentType.Name.AsSpan(), StringComparison.Ordinal)) { return(false); } currentType = (INamespaceOrTypeSymbol?)currentType.ContainingType ?? currentType.ContainingNamespace; roSpan = roSpan.Slice(0, dot > 0 ? dot : 0); } return(true); }
private async Task <Document> ProcessNodeAsync( Document document, SyntaxNode node, string containerName, INamespaceOrTypeSymbol?originalSymbol, CancellationToken cancellationToken ) { Contract.ThrowIfNull( originalSymbol, "Original symbol information missing. Haven't called GetContainers?" ); var newRoot = await ReplaceNodeAsync( node, containerName, originalSymbol.IsType, cancellationToken ) .ConfigureAwait(false); return(document.WithSyntaxRoot(newRoot)); }
public static IEnumerable <IPropertySymbol> GetIndexers(this INamespaceOrTypeSymbol?symbol) { return(symbol == null ? SpecializedCollections.EmptyEnumerable <IPropertySymbol>() : symbol.GetMembers(WellKnownMemberNames.Indexer).OfType <IPropertySymbol>().Where(p => p.IsIndexer)); }
/// <summary> /// Backing implementation of <see cref="LookupNamespacesAndTypes"/>. /// </summary> protected abstract ImmutableArray <ISymbol> LookupNamespacesAndTypesCore( int position, INamespaceOrTypeSymbol?container, string?name);
/// <summary> /// Backing implementation of <see cref="LookupSymbols"/>. /// </summary> protected abstract ImmutableArray <ISymbol> LookupSymbolsCore( int position, INamespaceOrTypeSymbol?container, string?name, bool includeReducedExtensionMethods);
public static ITypeSymbol?GetVtblAttribute(this INamespaceOrTypeSymbol?typeSymbol) { if (TypeToAttribute(typeSymbol, "SharpGen.Runtime.VtblAttribute") is not { ConstructorArguments : var args })