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


C# CodeGeneration.CodeGenerationOptions类代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationOptions的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerationOptions类的具体用法?C# CodeGenerationOptions怎么用?C# CodeGenerationOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CodeGenerationOptions类属于Microsoft.CodeAnalysis.CodeGeneration命名空间,在下文中一共展示了CodeGenerationOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddEnumMemberTo

        internal static EnumDeclarationSyntax AddEnumMemberTo(EnumDeclarationSyntax destination, IFieldSymbol enumMember, CodeGenerationOptions options)
        {
            var members = new List<SyntaxNodeOrToken>();
            members.AddRange(destination.Members.GetWithSeparators());

            var member = GenerateEnumMemberDeclaration(enumMember, destination, options);

            if (members.Count == 0)
            {
                members.Add(member);
            }
            else if (members.LastOrDefault().CSharpKind() == SyntaxKind.CommaToken)
            {
                members.Add(member);
                members.Add(SyntaxFactory.Token(SyntaxKind.CommaToken));
            }
            else
            {
                var lastMember = members.Last();
                var trailingTrivia = lastMember.GetTrailingTrivia();
                members[members.Count - 1] = lastMember.WithTrailingTrivia();
                members.Add(SyntaxFactory.Token(SyntaxKind.CommaToken).WithTrailingTrivia(trailingTrivia));
                members.Add(member);
            }

            return destination.EnsureOpenAndCloseBraceTokens()
                .WithMembers(SyntaxFactory.SeparatedList<EnumMemberDeclarationSyntax>(members));
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:28,代码来源:EnumMemberGenerator.cs

示例2: GenerateOperatorDeclarationWorker

        private static OperatorDeclarationSyntax GenerateOperatorDeclarationWorker(
            IMethodSymbol method,
            CodeGenerationDestination destination,
            CodeGenerationOptions options)
        {
            var hasNoBody = !options.GenerateMethodBodies || method.IsExtern;

            var operatorSyntaxKind = SyntaxFacts.GetOperatorKind(method.MetadataName);
            if (operatorSyntaxKind == SyntaxKind.None)
            {
                throw new ArgumentException(string.Format(WorkspacesResources.Cannot_generate_code_for_unsupported_operator_0, method.Name), nameof(method));
            }

            var operatorToken = SyntaxFactory.Token(operatorSyntaxKind);

            return SyntaxFactory.OperatorDeclaration(
                attributeLists: AttributeGenerator.GenerateAttributeLists(method.GetAttributes(), options),
                modifiers: GenerateModifiers(method),
                returnType: method.ReturnType.GenerateTypeSyntax(),
                operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword),
                operatorToken: operatorToken,
                parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, isExplicit: false, options: options),
                body: hasNoBody ? null : StatementGenerator.GenerateBlock(method),
                semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken());
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:25,代码来源:OperatorGenerator.cs

示例3: GenerateBracketedParameterList

 public static BracketedParameterListSyntax GenerateBracketedParameterList(
     ImmutableArray<IParameterSymbol> parameterDefinitions,
     bool isExplicit,
     CodeGenerationOptions options)
 {
     return GenerateBracketedParameterList((IList<IParameterSymbol>)parameterDefinitions, isExplicit, options);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:ParameterGenerator.cs

示例4: GenerateConversionDeclarationWorker

        private static ConversionOperatorDeclarationSyntax GenerateConversionDeclarationWorker(
            IMethodSymbol method,
            CodeGenerationDestination destination,
            CodeGenerationOptions options)
        {
            var hasNoBody = !options.GenerateMethodBodies || method.IsExtern;

            var reusableSyntax = GetReuseableSyntaxNodeForSymbol<ConversionOperatorDeclarationSyntax>(method, options);
            if (reusableSyntax != null)
            {
                return reusableSyntax;
            }

            var operatorToken = SyntaxFactory.Token(SyntaxFacts.GetOperatorKind(method.MetadataName));
            var keyword = method.MetadataName == WellKnownMemberNames.ImplicitConversionName
                ? SyntaxFactory.Token(SyntaxKind.ImplicitKeyword)
                : SyntaxFactory.Token(SyntaxKind.ExplicitKeyword);

            return SyntaxFactory.ConversionOperatorDeclaration(
                attributeLists: AttributeGenerator.GenerateAttributeLists(method.GetAttributes(), options),
                modifiers: GenerateModifiers(method),
                implicitOrExplicitKeyword: keyword,
                operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword),
                type: method.ReturnType.GenerateTypeSyntax(),
                parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, isExplicit: false, options: options),
                body: hasNoBody ? null : StatementGenerator.GenerateBlock(method),
                semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken());
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:28,代码来源:ConversionGenerator.cs

示例5: GenerateMethodDeclarationWorker

        private static MethodDeclarationSyntax GenerateMethodDeclarationWorker(
            IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            var hasNoBody = !options.GenerateMethodBodies ||
                            destination == CodeGenerationDestination.InterfaceType ||
                            method.IsAbstract;

            var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(method.ExplicitInterfaceImplementations);

            var returnType = method.ReturnsByRef
                ? method.ReturnType.GenerateRefTypeSyntax()
                : method.ReturnType.GenerateTypeSyntax();

            return AddCleanupAnnotationsTo(SyntaxFactory.MethodDeclaration(
                attributeLists: GenerateAttributes(method, options, explicitInterfaceSpecifier != null),
                modifiers: GenerateModifiers(method, destination, options),
                returnType: returnType,
                explicitInterfaceSpecifier: explicitInterfaceSpecifier,
                identifier: method.Name.ToIdentifierToken(),
                typeParameterList: GenerateTypeParameterList(method, options),
                parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, explicitInterfaceSpecifier != null, options),
                constraintClauses: GenerateConstraintClauses(method),
                body: hasNoBody ? null : StatementGenerator.GenerateBlock(method),
                expressionBody: default(ArrowExpressionClauseSyntax),
                semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken()));
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:26,代码来源:MethodGenerator.cs

示例6: GenerateNamedTypeDeclaration

        public static MemberDeclarationSyntax GenerateNamedTypeDeclaration(
            ICodeGenerationService service,
            INamedTypeSymbol namedType,
            CodeGenerationDestination destination,
            CodeGenerationOptions options,
            CancellationToken cancellationToken)
        {
            options = options ?? CodeGenerationOptions.Default;

            var declaration = GetDeclarationSyntaxWithoutMembers(namedType, destination, options);

            if (namedType.IsComImport)
            {
                // If we're generating a ComImport type, then do not attempt to do any
                // reordering of members.
                options = options.With(autoInsertionLocation: false, sortMembers: false);
            }

            // If we are generating members then make sure to exclude properties that cannot be generated.
            // Reason: Calling AddProperty on a propertysymbol that can't be generated (like one with params) causes
            // the getter and setter to get generated instead. Since the list of members is going to include
            // the method symbols for the getter and setter, we don't want to generate them twice.
            declaration = options.GenerateMembers && namedType.TypeKind != TypeKind.Delegate
                ? service.AddMembers(declaration,
                                     GetMembers(namedType).Where(s => s.Kind != SymbolKind.Property || PropertyGenerator.CanBeGenerated((IPropertySymbol)s)),
                                     options,
                                     cancellationToken)
                : declaration;

            return AddCleanupAnnotationsTo(ConditionallyAddDocumentationCommentTo(declaration, namedType, options));
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:31,代码来源:NamedTypeGenerator.cs

示例7: GenerateConstructorDeclaration

        internal static ConstructorDeclarationSyntax GenerateConstructorDeclaration(
            IMethodSymbol constructor, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            options = options ?? CodeGenerationOptions.Default;

            var reusableSyntax = GetReuseableSyntaxNodeForSymbol<ConstructorDeclarationSyntax>(constructor, options);
            if (reusableSyntax != null)
            {
                return reusableSyntax;
            }

            bool hasNoBody = !options.GenerateMethodBodies;

            var declaration = SyntaxFactory.ConstructorDeclaration(
                attributeLists: AttributeGenerator.GenerateAttributeLists(constructor.GetAttributes(), options),
                modifiers: GenerateModifiers(constructor, options),
                identifier: CodeGenerationConstructorInfo.GetTypeName(constructor).ToIdentifierToken(),
                parameterList: ParameterGenerator.GenerateParameterList(constructor.Parameters, isExplicit: false, options: options),
                initializer: GenerateConstructorInitializer(constructor),
                body: hasNoBody ? null : GenerateBlock(constructor),
                semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : default(SyntaxToken));

            return AddCleanupAnnotationsTo(
                ConditionallyAddDocumentationCommentTo(declaration, constructor, options));
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:25,代码来源:ConstructorGenerator.cs

示例8: GenerateTypeParameterList

 public static TypeParameterListSyntax GenerateTypeParameterList(
     ImmutableArray<ITypeParameterSymbol> typeParameters, CodeGenerationOptions options)
 {
     return typeParameters.Length == 0
         ? null
         : SyntaxFactory.TypeParameterList(
             SyntaxFactory.SeparatedList(typeParameters.Select(t => GenerateTypeParameter(t, options))));
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:8,代码来源:TypeParameterGenerator.cs

示例9: GenerateParameterList

        public static ParameterListSyntax GenerateParameterList(
            IEnumerable<IParameterSymbol> parameterDefinitions,
            bool isExplicit,
            CodeGenerationOptions options)
        {
            var parameters = GetParameters(parameterDefinitions, isExplicit, options);

            return SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters));
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:ParameterGenerator.cs

示例10: GenerateConversionDeclaration

 internal static ConversionOperatorDeclarationSyntax GenerateConversionDeclaration(
     IMethodSymbol method,
     CodeGenerationDestination destination,
     CodeGenerationOptions options)
 {
     var declaration = GenerateConversionDeclarationWorker(method, destination, options);
     return AddCleanupAnnotationsTo(AddAnnotationsTo(method,
         ConditionallyAddDocumentationCommentTo(declaration, method, options)));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:ConversionGenerator.cs

示例11: AddMethodTo

 internal static CompilationUnitSyntax AddMethodTo(
     CompilationUnitSyntax destination,
     IMethodSymbol method,
     CodeGenerationOptions options,
     IList<bool> availableIndices)
 {
     var declaration = GenerateMethodDeclaration(method, CodeGenerationDestination.CompilationUnit, options);
     var members = Insert(destination.Members, declaration, options, availableIndices, after: LastMethod);
     return destination.WithMembers(members.ToSyntaxList());
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:MethodGenerator.cs

示例12: GenerateAttributeDeclaration

 private static AttributeListSyntax GenerateAttributeDeclaration(
     AttributeData attribute, SyntaxToken? target, CodeGenerationOptions options)
 {
     var attributeSyntax = GenerateAttribute(attribute, options);
     return attributeSyntax == null
         ? null
         : SyntaxFactory.AttributeList(
             target.HasValue ? SyntaxFactory.AttributeTargetSpecifier(target.Value) : null,
             SyntaxFactory.SingletonSeparatedList(attributeSyntax));
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:10,代码来源:AttributeGenerator.cs

示例13: GenerateTypeParameter

        private static TypeParameterSyntax GenerateTypeParameter(ITypeParameterSymbol symbol, CodeGenerationOptions options)
        {
            var varianceKeyword =
                symbol.Variance == VarianceKind.In ? SyntaxFactory.Token(SyntaxKind.InKeyword) :
                symbol.Variance == VarianceKind.Out ? SyntaxFactory.Token(SyntaxKind.OutKeyword) : default(SyntaxToken);

            return SyntaxFactory.TypeParameter(
                AttributeGenerator.GenerateAttributeLists(symbol.GetAttributes(), options),
                varianceKeyword,
                symbol.Name.ToIdentifierToken());
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:TypeParameterGenerator.cs

示例14: UpdateNamedTypeDeclaration

 public static MemberDeclarationSyntax UpdateNamedTypeDeclaration(
     ICodeGenerationService service,
     MemberDeclarationSyntax declaration,
     IList<ISymbol> newMembers,
     CodeGenerationOptions options,
     CancellationToken cancellationToken)
 {
     declaration = RemoveAllMembers(declaration);
     declaration = service.AddMembers(declaration, newMembers, options, cancellationToken);
     return AddCleanupAnnotationsTo(declaration);
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:11,代码来源:NamedTypeGenerator.cs

示例15: AddNamedTypeTo

 public static CompilationUnitSyntax AddNamedTypeTo(
     ICodeGenerationService service,
     CompilationUnitSyntax destination,
     INamedTypeSymbol namedType,
     CodeGenerationOptions options,
     IList<bool> availableIndices)
 {
     var declaration = GenerateNamedTypeDeclaration(service, namedType, CodeGenerationDestination.CompilationUnit, options);
     var members = Insert(destination.Members, declaration, options, availableIndices);
     return destination.WithMembers(members);
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:11,代码来源:NamedTypeGenerator.cs


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