private static ImmutableArray <Location> ReadElementLocations(SymbolKeyReader reader) { using var elementLocations = reader.ReadLocationArray(); // Compiler API requires that all the locations are non-null, or that there is a default // immutable array passed in. if (elementLocations.Builder.All(loc => loc == null)) { return(default);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var isError = reader.ReadBoolean(); if (isError) { var elementTypes = reader.ReadSymbolKeyArray().SelectAsArray(r => r.GetAnySymbol() as ITypeSymbol); var elementNames = reader.ReadStringArray(); var elementLocations = reader.ReadLocationArray(); if (!elementTypes.Any(t => t == null)) { try { var result = reader.Compilation.CreateTupleTypeSymbol( elementTypes, elementNames, elementLocations); return(new SymbolKeyResolution(result)); } catch (ArgumentException) { } } } else { var underlyingTypeResolution = reader.ReadSymbolKey(); var elementNames = reader.ReadStringArray(); var elementLocations = reader.ReadLocationArray(); try { var result = GetAllSymbols <INamedTypeSymbol>(underlyingTypeResolution).Select( t => reader.Compilation.CreateTupleTypeSymbol(t, elementNames, elementLocations)); return(CreateSymbolInfo(result)); } catch (ArgumentException) { } } return(new SymbolKeyResolution(reader.Compilation.ObjectType)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var underlyingTypeResolution = reader.ReadSymbolKey(); var elementNames = reader.ReadStringArray(); var elementLocations = reader.ReadLocationArray(); try { var result = GetAllSymbols <INamedTypeSymbol>(underlyingTypeResolution).Select( t => reader.Compilation.CreateTupleTypeSymbol(t, elementNames, elementLocations)); return(CreateSymbolInfo(result)); } catch (ArgumentException) { return(new SymbolKeyResolution(reader.Compilation.ObjectType)); } }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var cancellationToken = reader.CancellationToken; var name = reader.ReadString(); var kind = (SymbolKind)reader.ReadInteger(); var locations = reader.ReadLocationArray(); var ordinal = reader.ReadInteger(); // First check if we can recover the symbol just through the original location. foreach (var loc in locations) { var resolutionOpt = reader.ResolveLocation(loc); if (resolutionOpt.HasValue) { var resolution = resolutionOpt.Value; var symbol = resolution.GetAnySymbol(); if (symbol?.Kind == kind && SymbolKey.Equals(reader.Compilation, name, symbol.Name)) { return(resolution); } } } // Couldn't recover. See if we can still find a match across the textual drift. if (ordinal != int.MaxValue && TryGetSemanticModel(reader.Compilation, locations[0].SourceTree, out var semanticModel)) { foreach (var symbol in EnumerateSymbols(semanticModel, kind, name, cancellationToken)) { if (symbol.ordinal == ordinal) { return(new SymbolKeyResolution(symbol.symbol)); } } } return(default);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var propertyTypeSymbols = reader.ReadSymbolKeyArray(); var propertyTypes = propertyTypeSymbols.Select(r => GetFirstSymbol <ITypeSymbol>(r)).ToImmutableArray(); var propertyNames = reader.ReadStringArray(); var propertyIsReadOnly = reader.ReadBooleanArray(); var propertyLocations = reader.ReadLocationArray(); if (propertyTypes.Length == propertyNames.Length) { try { var anonymousType = reader.Compilation.CreateAnonymousTypeSymbol( propertyTypes, propertyNames, propertyIsReadOnly, propertyLocations); return(new SymbolKeyResolution(anonymousType)); } catch (ArgumentException) { } } return(new SymbolKeyResolution(reader.Compilation.ObjectType)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { using var propertyTypes = reader.ReadSymbolKeyArray <ITypeSymbol>(); using var propertyNames = reader.ReadStringArray(); using var propertyIsReadOnly = reader.ReadBooleanArray(); using var propertyLocations = reader.ReadLocationArray(); if (!propertyTypes.IsDefault) { try { var anonymousType = reader.Compilation.CreateAnonymousTypeSymbol( propertyTypes.ToImmutable(), propertyNames.ToImmutable(), propertyIsReadOnly.ToImmutable(), propertyLocations.ToImmutable()); return(new SymbolKeyResolution(anonymousType)); } catch (ArgumentException) { } } return(new SymbolKeyResolution(reader.Compilation.ObjectType)); }