Esempio n. 1
0
        public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration)
        {
            FixAttributes(operatorDeclaration);

            ForceSpacesBefore(operatorDeclaration.LParToken, policy.SpaceBeforeMethodDeclarationParentheses);
            if (operatorDeclaration.Parameters.Any())
            {
                ForceSpacesAfter(operatorDeclaration.LParToken, policy.SpaceWithinMethodDeclarationParentheses);
                FormatArguments(operatorDeclaration);
            }
            else
            {
                ForceSpacesAfter(operatorDeclaration.LParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses);
                ForceSpacesBefore(operatorDeclaration.RParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses);
            }

            if (!operatorDeclaration.Body.IsNull)
            {
                FixOpenBrace(policy.MethodBraceStyle, operatorDeclaration.Body.LBraceToken);
                VisitBlockWithoutFixingBraces(operatorDeclaration.Body, policy.IndentMethodBody);
                FixClosingBrace(policy.MethodBraceStyle, operatorDeclaration.Body.RBraceToken);
            }
        }
Esempio n. 2
0
 void IAstVisitor.VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration)
 {
     Visit(EnterOperatorDeclaration, LeaveOperatorDeclaration, operatorDeclaration);
 }
        void WriteMemberDeclarationName(IMember member, IOutputFormatter formatter, CSharpFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();

            if ((ConversionFlags & ConversionFlags.ShowDeclaringType) == ConversionFlags.ShowDeclaringType)
            {
                ConvertType(member.DeclaringType, formatter, formattingPolicy);
                formatter.WriteToken(".");
            }
            switch (member.EntityType)
            {
            case EntityType.Indexer:
                formatter.WriteKeyword("this");
                break;

            case EntityType.Constructor:
                formatter.WriteIdentifier(member.DeclaringType.Name);
                break;

            case EntityType.Destructor:
                formatter.WriteToken("~");
                formatter.WriteIdentifier(member.DeclaringType.Name);
                break;

            case EntityType.Operator:
                switch (member.Name)
                {
                case "op_Implicit":
                    formatter.WriteKeyword("implicit");
                    formatter.Space();
                    formatter.WriteKeyword("operator");
                    formatter.Space();
                    ConvertType(member.ReturnType, formatter, formattingPolicy);
                    break;

                case "op_Explicit":
                    formatter.WriteKeyword("explicit");
                    formatter.Space();
                    formatter.WriteKeyword("operator");
                    formatter.Space();
                    ConvertType(member.ReturnType, formatter, formattingPolicy);
                    break;

                default:
                    formatter.WriteKeyword("operator");
                    formatter.Space();
                    var operatorType = OperatorDeclaration.GetOperatorType(member.Name);
                    if (operatorType.HasValue)
                    {
                        formatter.WriteToken(OperatorDeclaration.GetToken(operatorType.Value));
                    }
                    else
                    {
                        formatter.WriteIdentifier(member.Name);
                    }
                    break;
                }
                break;

            default:
                formatter.WriteIdentifier(member.Name);
                break;
            }
            if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList && member.EntityType == EntityType.Method)
            {
                var outputVisitor = new CSharpOutputVisitor(formatter, formattingPolicy);
                outputVisitor.WriteTypeParameters(astBuilder.ConvertEntity(member).GetChildrenByRole(Roles.TypeParameter));
            }
        }