コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ElementDescription"/> class.
        /// </summary>
        /// <param name="symbol">The roslyn symbol to wrap.</param>
        protected ElementDescription(ISymbol symbol)
        {
            Debug.Assert(!symbol.IsImplicitlyDeclared, $"{nameof(ElementDescription)} does not support compiler generated types");
            this.Symbol = symbol;

            // Initialize parent element based on underlying symbol.
            this.Parent = this.Symbol.ContainingSymbol switch
            {
                IErrorTypeSymbol e => new MissingMetadataTypeDescription(e),
                INamedTypeSymbol n => new MetadataTypeDescription(n),
                _ => null,
            };
        }
コード例 #2
0
        private static IEnumerable <INamedTypeSymbol> Unwrap(INamedTypeSymbol namedType)
        {
            yield return(namedType);

            IErrorTypeSymbol errorType = namedType as IErrorTypeSymbol;

            if (errorType != null)
            {
                foreach (var type in errorType.CandidateSymbols.OfType <INamedTypeSymbol>())
                {
                    yield return(type);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataTypeDescription"/> class.
 /// </summary>
 /// <param name="symbol">The wrapped roslyn symbol.</param>
 internal MetadataTypeDescription(INamedTypeSymbol symbol)
     : base(symbol)
 {
     // This constructor can be called only for INamedTypeSymbols proper, unless it is itself a subclass.
     Debug.Assert(this.GetType() != typeof(MetadataTypeDescription) || this.Symbol is INamedTypeSymbol, $"Cannot pass a symbol of type {this.Symbol.TypeKind} directly to {nameof(MetadataTypeDescription)}");
     this.BaseType = this.Symbol.BaseType switch
     {
         IErrorTypeSymbol e => new MissingMetadataTypeDescription(e),
         INamedTypeSymbol n => new MetadataTypeDescription(n),
         null => null,
     };
     var interfaceQuery = from i in this.Symbol.Interfaces
                          select i switch
     {
         IErrorTypeSymbol e => new MissingMetadataTypeDescription(e),
         INamedTypeSymbol n => new MetadataTypeDescription(n),
     };
     this.Interfaces = interfaceQuery.ToImmutableArray();
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingMetadataTypeDescription"/> class.
 /// </summary>
 /// <param name="symbol">An instance of <see cref="IErrorTypeSymbol"/>.</param>
 internal MissingMetadataTypeDescription(IErrorTypeSymbol symbol)
     : base(symbol)
 {
 }