当前位置: 首页>>代码示例>>C#>>正文


C# IOutputFormatter.WriteToken方法代码示例

本文整理汇总了C#中IOutputFormatter.WriteToken方法的典型用法代码示例。如果您正苦于以下问题:C# IOutputFormatter.WriteToken方法的具体用法?C# IOutputFormatter.WriteToken怎么用?C# IOutputFormatter.WriteToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOutputFormatter的用法示例。


在下文中一共展示了IOutputFormatter.WriteToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteTypeDeclarationName

 void WriteTypeDeclarationName(ITypeDefinition typeDef, IOutputFormatter formatter, CSharpFormattingOptions formattingPolicy)
 {
     TypeSystemAstBuilder astBuilder = CreateAstBuilder();
     if (typeDef.DeclaringTypeDefinition != null) {
         WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, formatter, formattingPolicy);
         formatter.WriteToken(".");
     } else if ((ConversionFlags & ConversionFlags.UseFullyQualifiedTypeNames) == ConversionFlags.UseFullyQualifiedTypeNames) {
         formatter.WriteIdentifier(typeDef.Namespace);
         formatter.WriteToken(".");
     }
     formatter.WriteIdentifier(typeDef.Name);
     if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList) {
         var outputVisitor = new CSharpOutputVisitor(formatter, formattingPolicy);
         outputVisitor.WriteTypeParameters(astBuilder.ConvertEntity(typeDef).GetChildrenByRole(Roles.TypeParameter));
     }
 }
开发者ID:segaman,项目名称:NRefactory,代码行数:16,代码来源:CSharpAmbience.cs

示例2: ConvertEntity

        public void ConvertEntity(IEntity entity, IOutputFormatter formatter, CSharpFormattingOptions formattingPolicy)
        {
            if (entity == null)
                throw new ArgumentNullException("entity");
            if (formatter == null)
                throw new ArgumentNullException("formatter");
            if (formattingPolicy == null)
                throw new ArgumentNullException("options");

            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            EntityDeclaration node = astBuilder.ConvertEntity(entity);
            PrintModifiers(node.Modifiers, formatter);

            if ((ConversionFlags & ConversionFlags.ShowDefinitionKeyword) == ConversionFlags.ShowDefinitionKeyword) {
                if (node is TypeDeclaration) {
                    switch (((TypeDeclaration)node).ClassType) {
                        case ClassType.Class:
                            formatter.WriteKeyword("class");
                            break;
                        case ClassType.Struct:
                            formatter.WriteKeyword("struct");
                            break;
                        case ClassType.Interface:
                            formatter.WriteKeyword("interface");
                            break;
                        case ClassType.Enum:
                            formatter.WriteKeyword("enum");
                            break;
                        default:
                            throw new Exception("Invalid value for ClassType");
                    }
                    formatter.Space();
                } else if (node is DelegateDeclaration) {
                    formatter.WriteKeyword("delegate");
                    formatter.Space();
                } else if (node is EventDeclaration) {
                    formatter.WriteKeyword("event");
                    formatter.Space();
                }
            }

            if ((ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) {
                var rt = node.GetChildByRole(Roles.Type);
                if (!rt.IsNull) {
                    rt.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
                    formatter.Space();
                }
            }

            if (entity is ITypeDefinition)
                WriteTypeDeclarationName((ITypeDefinition)entity, formatter, formattingPolicy);
            else
                WriteMemberDeclarationName((IMember)entity, formatter, formattingPolicy);

            if ((ConversionFlags & ConversionFlags.ShowParameterList) == ConversionFlags.ShowParameterList && HasParameters(entity)) {
                formatter.WriteToken(entity.EntityType == EntityType.Indexer ? "[" : "(");
                bool first = true;
                foreach (var param in node.GetChildrenByRole(Roles.Parameter)) {
                    if (first) {
                        first = false;
                    } else {
                        formatter.WriteToken(",");
                        formatter.Space();
                    }
                    param.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
                }
                formatter.WriteToken(entity.EntityType == EntityType.Indexer ? "]" : ")");
            }

            if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration)) {
                IProperty property = entity as IProperty;
                if (property != null) {
                    formatter.Space();
                    formatter.WriteToken("{");
                    formatter.Space();
                    if (property.CanGet) {
                        formatter.WriteKeyword("get");
                        formatter.WriteToken(";");
                        formatter.Space();
                    }
                    if (property.CanSet) {
                        formatter.WriteKeyword("set");
                        formatter.WriteToken(";");
                        formatter.Space();
                    }
                    formatter.WriteToken("}");
                } else {
                    formatter.WriteToken(";");
                }
            }
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:91,代码来源:CSharpAmbience.cs

示例3: WriteMemberDeclarationName

 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));
     }
 }
开发者ID:segaman,项目名称:NRefactory,代码行数:54,代码来源:CSharpAmbience.cs


注:本文中的IOutputFormatter.WriteToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。