Пример #1
0
        public static void BuildNamedTypeDisplayName(this INamedTypeSymbol namedType, Context cx, ITrapBuilder tb)
        {
            if (namedType.IsTupleType)
            {
                tb.Append("(");
                tb.BuildList(",", namedType.TupleElements.Select(f => f.Type),
                             (t, tb0) => t.BuildDisplayName(cx, tb0)
                             );

                tb.Append(")");
                return;
            }

            if (namedType.IsAnonymousType)
            {
                namedType.BuildAnonymousName(cx, tb, (cx0, tb0, sub) => sub.BuildDisplayName(cx0, tb0), false);
            }

            tb.Append(namedType.Name);
            if (namedType.IsGenericType && namedType.TypeKind != TypeKind.Error && namedType.TypeArguments.Any())
            {
                tb.Append("<");
                tb.BuildList(",", namedType.TypeArguments, (p, tb0) =>
                {
                    if (IsReallyBound(namedType))
                    {
                        p.BuildDisplayName(cx, tb0);
                    }
                });
                tb.Append(">");
            }
        }
Пример #2
0
        public static void BuildNamedTypeDisplayName(this INamedTypeSymbol namedType, Context cx, TextWriter trapFile)
        {
            if (namedType.IsTupleType)
            {
                trapFile.Write('(');
                trapFile.BuildList(",", namedType.TupleElements.Select(f => f.Type),
                                   (t, tb0) => t.BuildDisplayName(cx, tb0)
                                   );

                trapFile.Write(")");
                return;
            }

            if (namedType.IsAnonymousType)
            {
                namedType.BuildAnonymousName(cx, trapFile, (cx0, tb0, sub) => sub.BuildDisplayName(cx0, tb0), false);
            }

            trapFile.Write(namedType.Name);
            if (namedType.IsGenericType && namedType.TypeKind != TypeKind.Error && namedType.TypeArguments.Any())
            {
                trapFile.Write('<');
                trapFile.BuildList(",", namedType.TypeArguments, (p, tb0) =>
                {
                    if (IsReallyBound(namedType))
                    {
                        p.BuildDisplayName(cx, tb0);
                    }
                });
                trapFile.Write('>');
            }
        }
Пример #3
0
        static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter trapFile, Action <Context, TextWriter, ITypeSymbol> subTermAction)
        {
            if (named.IsTupleType)
            {
                trapFile.Write('(');
                trapFile.BuildList(",", named.TupleElements,
                                   (f, tb0) =>
                {
                    trapFile.Write(f.Name);
                    trapFile.Write(":");
                    subTermAction(cx, tb0, f.Type);
                }
                                   );
                trapFile.Write(")");
                return;
            }

            if (named.ContainingType != null)
            {
                subTermAction(cx, trapFile, named.ContainingType);
                trapFile.Write('.');
            }
            else if (named.ContainingNamespace != null)
            {
                named.ContainingNamespace.BuildNamespace(cx, trapFile);
            }

            if (named.IsAnonymousType)
            {
                named.BuildAnonymousName(cx, trapFile, subTermAction, true);
            }
            else if (named.TypeParameters.IsEmpty)
            {
                trapFile.Write(named.Name);
            }
            else if (IsReallyUnbound(named))
            {
                trapFile.Write(named.Name);
                trapFile.Write("`");
                trapFile.Write(named.TypeParameters.Length);
            }
            else
            {
                subTermAction(cx, trapFile, named.ConstructedFrom);
                trapFile.Write('<');
                // Encode the nullability of the type arguments in the label.
                // Type arguments with different nullability can result in
                // a constructed type with different nullability of its members and methods,
                // so we need to create a distinct database entity for it.
                trapFile.BuildList(",", named.GetAnnotatedTypeArguments(), (ta, tb0) => { subTermAction(cx, tb0, ta.Symbol); trapFile.Write((int)ta.Nullability); });
                trapFile.Write('>');
            }
        }
Пример #4
0
        static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, ITrapBuilder tb, Action <Context, ITrapBuilder, ITypeSymbol> subTermAction)
        {
            if (named.IsTupleType)
            {
                tb.Append("(");
                tb.BuildList(",", named.TupleElements,
                             (f, tb0) =>
                {
                    tb.Append(f.Name).Append(":");
                    subTermAction(cx, tb0, f.Type);
                }
                             );
                tb.Append(")");
                return;
            }

            if (named.ContainingType != null)
            {
                subTermAction(cx, tb, named.ContainingType);
                tb.Append(".");
            }
            else if (named.ContainingNamespace != null)
            {
                named.ContainingNamespace.BuildNamespace(cx, tb);
            }

            if (named.IsAnonymousType)
            {
                named.BuildAnonymousName(cx, tb, subTermAction, true);
            }
            else if (named.TypeParameters.IsEmpty)
            {
                tb.Append(named.Name);
            }
            else if (IsReallyUnbound(named))
            {
                tb.Append(named.Name).Append("`").Append(named.TypeParameters.Length);
            }
            else
            {
                subTermAction(cx, tb, named.ConstructedFrom);
                tb.Append("<");
                tb.BuildList(",", named.TypeArguments, (ta, tb0) => subTermAction(cx, tb0, ta));
                tb.Append(">");
            }
        }