Exemplo n.º 1
0
        void WriteMemberDeclarationName(IMember member, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            EntityDeclaration    node       = astBuilder.ConvertEntity(member);

            switch (member.SymbolKind)
            {
            case SymbolKind.Indexer:
                writer.WriteKeyword(Roles.Identifier, "this");
                break;

            case SymbolKind.Constructor:
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                var typeNode = astBuilder.ConvertEntity(member.DeclaringTypeDefinition);
                WriteTypeParameters(writer, typeNode.GetChildrenByRole(Roles.TypeParameter));
                break;

            case SymbolKind.Destructor:
                writer.WriteToken(DestructorDeclaration.TildeRole, "~");
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                break;

            case SymbolKind.Operator:
                switch (member.Name)
                {
                case "op_Implicit":
                    writer.WriteKeyword(OperatorDeclaration.ImplicitRole, "implicit");
                    writer.Space();
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    ConvertType(member.ReturnType, writer, formattingPolicy);
                    break;

                case "op_Explicit":
                    writer.WriteKeyword(OperatorDeclaration.ExplicitRole, "explicit");
                    writer.Space();
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    ConvertType(member.ReturnType, writer, formattingPolicy);
                    break;

                default:
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    var operatorType = OperatorDeclaration.GetOperatorType(member.Name);
                    if (operatorType.HasValue)
                    {
                        writer.WriteToken(OperatorDeclaration.GetRole(operatorType.Value), OperatorDeclaration.GetToken(operatorType.Value));
                    }
                    else
                    {
                        writer.WriteIdentifier(node.NameToken);
                    }
                    break;
                }
                break;

            default:
                writer.WriteIdentifier(Identifier.Create(member.Name));
                IEnumerable <AstNode> typeArgs = node.GetChildrenByRole(Roles.TypeParameter);
                if (member is IMethod)
                {
                    var typeArguments = ((IMethod)member).TypeArguments;
                    if (typeArguments.Any() && typeArguments.First().Name == "TSource")
                    {
                        typeArgs = typeArgs.Skip(1);
                    }
                }
                WriteTypeParameters(writer, typeArgs);
                break;
            }
        }
Exemplo n.º 2
0
        void WriteMemberDeclarationName(IMember member, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            EntityDeclaration    node       = astBuilder.ConvertEntity(member);

            switch (member.SymbolKind)
            {
            case SymbolKind.Indexer:
                writer.WriteKeyword(Roles.Identifier, "this");
                break;

            case SymbolKind.Constructor:
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                var typeNode = astBuilder.ConvertEntity(member.DeclaringTypeDefinition);
                WriteTypeParameters(writer, typeNode.GetChildrenByRole(Roles.TypeParameter));
                break;

            case SymbolKind.Destructor:
                writer.WriteToken(DestructorDeclaration.TildeRole, "~");
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                break;

            case SymbolKind.Operator:
                switch (member.Name)
                {
                case "op_Implicit":
                    writer.WriteKeyword(OperatorDeclaration.ImplicitRole, "implicit");
                    writer.Space();
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    ConvertType(member.ReturnType, writer, formattingPolicy);
                    break;

                case "op_Explicit":
                    writer.WriteKeyword(OperatorDeclaration.ExplicitRole, "explicit");
                    writer.Space();
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    ConvertType(member.ReturnType, writer, formattingPolicy);
                    break;

                default:
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    var operatorType = OperatorDeclaration.GetOperatorType(member.Name);
                    if (operatorType.HasValue)
                    {
                        writer.WriteToken(OperatorDeclaration.GetRole(operatorType.Value), OperatorDeclaration.GetToken(operatorType.Value));
                    }
                    else
                    {
                        writer.WriteIdentifier(node.NameToken);
                    }
                    break;
                }
                break;

            default:
                writer.WriteIdentifier(Identifier.Create(member.Name));
                if (member is IMethod)
                {
                    var method = ((IMethod)member);

                    var methodParameterTypeArguments =
                        from p in method.Parameters
                        from type in ExpandIntersections(p.Type)
                        from typeArgument in type.TypeArguments
                        select typeArgument.Name;

                    IEnumerable <AstNode> typeArgs = node.GetChildrenByRole(Roles.TypeParameter).Where(arg => !methodParameterTypeArguments.Contains(arg.Name));
                    WriteTypeParameters(writer, typeArgs);
                }
                break;
            }
        }