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


C# MemberDeclarationSyntax.Kind方法代码示例

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


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

示例1: MemberOrderHelper

        /// <summary>
        /// Initializes a new instance of the <see cref="MemberOrderHelper"/> struct.
        /// </summary>
        /// <param name="member">The member to wrap.</param>
        /// <param name="elementOrder">The element ordering traits.</param>
        internal MemberOrderHelper(MemberDeclarationSyntax member, ImmutableArray<OrderingTrait> elementOrder)
        {
            this.Member = member;
            var modifiers = member.GetModifiers();
            var type = member.Kind();
            type = type == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : type;

            this.Priority = 0;
            foreach (OrderingTrait trait in elementOrder)
            {
                switch (trait)
                {
                case OrderingTrait.Kind:
                    // 4 bits are required to store this.
                    this.Priority <<= 4;
                    this.Priority |= TypeMemberOrder.IndexOf(type) & 0x0F;
                    break;

                case OrderingTrait.Accessibility:
                    // 3 bits are required to store this.
                    this.Priority <<= 3;
                    this.Priority |= (int)GetAccessLevelForOrdering(member, modifiers) & 0x07;
                    break;

                case OrderingTrait.Constant:
                    this.Priority <<= 1;
                    if (modifiers.Any(SyntaxKind.ConstKeyword))
                    {
                        this.Priority |= 1;
                    }

                    break;

                case OrderingTrait.Static:
                    this.Priority <<= 1;
                    if (modifiers.Any(SyntaxKind.StaticKeyword))
                    {
                        this.Priority |= 1;
                    }

                    break;

                case OrderingTrait.Readonly:
                    this.Priority <<= 1;
                    if (modifiers.Any(SyntaxKind.ReadOnlyKeyword))
                    {
                        this.Priority |= 1;
                    }

                    break;

                default:
                    continue;
                }
            }
        }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:61,代码来源:MemberOrderHelper.cs

示例2: AfterMember

        private static MemberDeclarationSyntax AfterMember(
            SyntaxList<MemberDeclarationSyntax> members,
            MemberDeclarationSyntax eventDeclaration)
        {
            if (eventDeclaration.Kind() == SyntaxKind.EventFieldDeclaration)
            {
                // Field style events go after the last field event, or after the last field.
                var lastEvent = members.LastOrDefault(m => m is EventFieldDeclarationSyntax);

                return lastEvent ?? LastField(members);
            }

            if (eventDeclaration.Kind() == SyntaxKind.EventDeclaration)
            {
                // Property style events go after existing events, then after existing constructors.
                var lastEvent = members.LastOrDefault(m => m is EventDeclarationSyntax);

                return lastEvent ?? LastConstructor(members);
            }

            return null;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:22,代码来源:EventGenerator.cs

示例3: BeforeMember

        private static MemberDeclarationSyntax BeforeMember(
            SyntaxList<MemberDeclarationSyntax> members,
            MemberDeclarationSyntax eventDeclaration)
        {
            // If it's a field style event, then it goes before everything else if we don't have any
            // existing fields/events.
            if (eventDeclaration.Kind() == SyntaxKind.FieldDeclaration)
            {
                return members.FirstOrDefault();
            }

            // Otherwise just place it before the methods.
            return FirstMethod(members);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:14,代码来源:EventGenerator.cs

示例4: IsEvalCandidate

        public static bool IsEvalCandidate(this SemanticModel model, MemberDeclarationSyntax member)
        {
            if (member.Kind() != SyntaxKind.FieldDeclaration)
                return false;
            var field = member as FieldDeclarationSyntax;
            var attrDeclares = field.AttributeLists;
            foreach (var attrDeclare in attrDeclares)
            {
                foreach (var attr in attrDeclare.Attributes)
                {
                    var type = model.GetTypeInfo(attr);
                    if (type.Type.IsSameType(nameof(JavaScript), nameof(EvalAtCompileAttribute)))
                        return true;
                }
            }

            return false;
        }
开发者ID:rexzh,项目名称:SharpJs,代码行数:18,代码来源:SemanticModelExtension.cs

示例5: MemberOrderHelper

        /// <summary>
        /// Initializes a new instance of the <see cref="MemberOrderHelper"/> struct.
        /// </summary>
        /// <param name="member">The member to wrap.</param>
        /// <param name="checks">The element ordering checks.</param>
        internal MemberOrderHelper(MemberDeclarationSyntax member, ElementOrderingChecks checks)
        {
            this.Member = member;
            var modifiers = member.GetModifiers();
            var type = member.Kind();
            type = type == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : type;

            this.elementPriority = checks.ElementType ? TypeMemberOrder.IndexOf(type) : 0;
            this.modifierFlags = GetModifierFlags(modifiers, checks);
            if (checks.AccessLevel)
            {
                if ((type == SyntaxKind.ConstructorDeclaration && this.modifierFlags.HasFlag(ModifierFlags.Static))
                    || (type == SyntaxKind.MethodDeclaration && ((MethodDeclarationSyntax)member).ExplicitInterfaceSpecifier != null)
                    || (type == SyntaxKind.PropertyDeclaration && ((PropertyDeclarationSyntax)member).ExplicitInterfaceSpecifier != null)
                    || (type == SyntaxKind.IndexerDeclaration && ((IndexerDeclarationSyntax)member).ExplicitInterfaceSpecifier != null))
                {
                    this.accessibilty = AccessLevel.Public;
                }
                else
                {
                    this.accessibilty = AccessLevelHelper.GetAccessLevel(modifiers);
                    if (this.accessibilty == AccessLevel.NotSpecified)
                    {
                        if (member.Parent.IsKind(SyntaxKind.CompilationUnit) || member.Parent.IsKind(SyntaxKind.NamespaceDeclaration))
                        {
                            this.accessibilty = AccessLevel.Internal;
                        }
                        else
                        {
                            this.accessibilty = AccessLevel.Private;
                        }
                    }
                }
            }
            else
            {
                this.accessibilty = AccessLevel.Public;
            }
        }
开发者ID:hexuefengx,项目名称:StyleCopAnalyzers,代码行数:44,代码来源:MemberOrderHelper.cs

示例6: CompareNamespacesOrTypes

            private bool CompareNamespacesOrTypes(
                MemberDeclarationSyntax oldNamespaceOrType,
                MemberDeclarationSyntax newNamespaceOrType,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                // If the kind doesn't match, it has to be a remove/add.
                if (oldNamespaceOrType.Kind() != newNamespaceOrType.Kind())
                {
                    EnqueueRemoveEvent(oldNamespaceOrType, newNodeParent, eventQueue);
                    EnqueueAddEvent(newNamespaceOrType, newNodeParent, eventQueue);

                    return false;
                }

                if (oldNamespaceOrType is BaseTypeDeclarationSyntax ||
                    oldNamespaceOrType is DelegateDeclarationSyntax)
                {
                    return CompareTypeDeclarations(oldNamespaceOrType, newNamespaceOrType, newNodeParent, eventQueue);
                }
                else if (oldNamespaceOrType is NamespaceDeclarationSyntax)
                {
                    return CompareNamespaceDeclarations((NamespaceDeclarationSyntax)oldNamespaceOrType, (NamespaceDeclarationSyntax)newNamespaceOrType, newNodeParent, eventQueue);
                }

                return false;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:27,代码来源:CSharpCodeModelService.CodeModelEventCollector.cs

示例7: CompareTypeDeclarations

            private bool CompareTypeDeclarations(
                MemberDeclarationSyntax oldMember,
                MemberDeclarationSyntax newMember,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldMember != null && newMember != null);
                Debug.Assert(oldMember is BaseTypeDeclarationSyntax || oldMember is DelegateDeclarationSyntax);
                Debug.Assert(newMember is BaseTypeDeclarationSyntax || newMember is DelegateDeclarationSyntax);

                // If the kind doesn't match, it has to be a remove/add.
                if (oldMember.Kind() != newMember.Kind())
                {
                    EnqueueRemoveEvent(oldMember, newNodeParent, eventQueue);
                    EnqueueAddEvent(newMember, newNodeParent, eventQueue);

                    return false;
                }

                if (oldMember is BaseTypeDeclarationSyntax)
                {
                    var oldType = (BaseTypeDeclarationSyntax)oldMember;
                    var newType = (BaseTypeDeclarationSyntax)newMember;

                    var oldMembers = GetValidMembers(oldType);
                    var newMembers = GetValidMembers(newType);

                    bool same = true;

                    // If the type name is different, it might mean that the whole type has been removed and a new one added.
                    // In that case, we shouldn't do any other checks and instead return immediately.
                    if (!StringComparer.Ordinal.Equals(oldType.Identifier.ToString(), newType.Identifier.ToString()))
                    {
                        var change = CompareRenamedDeclarations(
                            CompareMemberDeclarations,
                            oldMembers,
                            newMembers,
                            oldType,
                            newType,
                            newNodeParent,
                            eventQueue);

                        if (change == DeclarationChange.WholeDeclaration)
                        {
                            return false;
                        }

                        same = false;
                        EnqueueChangeEvent(newType, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    }

                    if (!CompareModifiers(oldType, newType))
                    {
                        same = false;
                        EnqueueChangeEvent(newType, newNodeParent, CodeModelEventType.Unknown, eventQueue);
                    }

                    if (!CompareBaseLists(oldType, newType))
                    {
                        same = false;
                        EnqueueChangeEvent(newType, newNodeParent, CodeModelEventType.BaseChange, eventQueue);
                    }

                    same &= CompareChildren(
                        CompareAttributeLists,
                        oldType.AttributeLists.AsReadOnlyList(),
                        newType.AttributeLists.AsReadOnlyList(),
                        newType,
                        CodeModelEventType.Unknown,
                        eventQueue);

                    same &= CompareChildren(
                        CompareMemberDeclarations,
                        oldMembers,
                        newMembers,
                        newType,
                        CodeModelEventType.Unknown,
                        eventQueue);

                    return same;
                }
                else if (oldMember is DelegateDeclarationSyntax)
                {
                    var oldDelegate = (DelegateDeclarationSyntax)oldMember;
                    var newDelegate = (DelegateDeclarationSyntax)newMember;

                    bool same = true;

                    // If the delegate name is different, it might mean that the whole delegate has been removed and a new one added.
                    // In that case, we shouldn't do any other checks and instead return immediately.
                    if (!StringComparer.Ordinal.Equals(oldDelegate.Identifier.ToString(), newDelegate.Identifier.ToString()))
                    {
                        var change = CompareRenamedDeclarations(
                            CompareParameters,
                            oldDelegate.ParameterList.Parameters.AsReadOnlyList(),
                            newDelegate.ParameterList.Parameters.AsReadOnlyList(),
                            oldDelegate,
                            newDelegate,
                            newNodeParent,
                            eventQueue);
//.........这里部分代码省略.........
开发者ID:Rickinio,项目名称:roslyn,代码行数:101,代码来源:CSharpCodeModelService.CodeModelEventCollector.cs

示例8: CompareMemberDeclarations

            private bool CompareMemberDeclarations(
                MemberDeclarationSyntax oldMember,
                MemberDeclarationSyntax newMember,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldMember != null && newMember != null);

                // If the kind doesn't match, it has to be a remove/add.
                if (oldMember.Kind() != newMember.Kind())
                {
                    EnqueueRemoveEvent(oldMember, newNodeParent, eventQueue);
                    EnqueueAddEvent(newMember, newNodeParent, eventQueue);

                    return false;
                }

                if (oldMember is BaseTypeDeclarationSyntax ||
                    oldMember is DelegateDeclarationSyntax)
                {
                    return CompareTypeDeclarations(oldMember, newMember, newNodeParent, eventQueue);
                }
                else if (oldMember is BaseMethodDeclarationSyntax)
                {
                    return CompareMethodDeclarations((BaseMethodDeclarationSyntax)oldMember, (BaseMethodDeclarationSyntax)newMember, newNodeParent, eventQueue);
                }
                else if (oldMember is BaseFieldDeclarationSyntax)
                {
                    return CompareFieldDeclarations((BaseFieldDeclarationSyntax)oldMember, (BaseFieldDeclarationSyntax)newMember, newNodeParent, eventQueue);
                }
                else if (oldMember is BasePropertyDeclarationSyntax)
                {
                    return ComparePropertyDeclarations((BasePropertyDeclarationSyntax)oldMember, (BasePropertyDeclarationSyntax)newMember, newNodeParent, eventQueue);
                }
                else if (oldMember is EnumMemberDeclarationSyntax)
                {
                    return CompareEnumMemberDeclarations((EnumMemberDeclarationSyntax)oldMember, (EnumMemberDeclarationSyntax)newMember, newNodeParent, eventQueue);
                }

                throw new NotImplementedException();
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:41,代码来源:CSharpCodeModelService.CodeModelEventCollector.cs

示例9: GetDeclaredSymbol

        /// <summary>
        /// Given an member declaration syntax, get the corresponding symbol.
        /// </summary>
        /// <param name="declarationSyntax">The syntax node that declares a member.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The symbol that was declared.</returns>
        /// <remarks>
        /// NOTE:   We have no GetDeclaredSymbol overloads for following subtypes of MemberDeclarationSyntax:
        /// NOTE:   (1) GlobalStatementSyntax as they don't declare any symbols.
        /// NOTE:   (2) IncompleteMemberSyntax as there are no symbols for incomplete members.
        /// NOTE:   (3) BaseFieldDeclarationSyntax or its subtypes as these declarations can contain multiple variable declarators.
        /// NOTE:       GetDeclaredSymbol should be called on the variable declarators directly.
        /// </remarks>
        public override ISymbol GetDeclaredSymbol(MemberDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
        {
            CheckSyntaxNode(declarationSyntax);

            switch (declarationSyntax.Kind())
            {
                // Few subtypes of MemberDeclarationSyntax don't declare any symbols or declare multiple symbols, return null for these cases.

                case SyntaxKind.GlobalStatement:
                    // Global statements don't declare anything, even though they inherit from MemberDeclarationSyntax.
                    return null;

                case SyntaxKind.IncompleteMember:
                    // Incomplete members don't declare any symbols.
                    return null;

                case SyntaxKind.EventFieldDeclaration:
                case SyntaxKind.FieldDeclaration:
                    // these declarations can contain multiple variable declarators. GetDeclaredSymbol should be called on them directly.
                    return null;

                default:
                    return GetDeclaredNamespaceOrType(declarationSyntax) ?? GetDeclaredMemberSymbol(declarationSyntax);
            }
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:38,代码来源:SyntaxTreeSemanticModel.cs

示例10: CheckDeclarationName

        private static void CheckDeclarationName(MemberDeclarationSyntax member, SyntaxToken identifier, SyntaxNodeAnalysisContext context)
        {
            var symbol = context.SemanticModel.GetDeclaredSymbol(member);
            if (ClassName.IsTypeComRelated(symbol?.ContainingType) ||
                symbol.IsInterfaceImplementationOrMemberOverride() ||
                symbol.IsExtern)
            {
                return;
            }

            if (identifier.ValueText.StartsWith("_", StringComparison.Ordinal) ||
                identifier.ValueText.EndsWith("_", StringComparison.Ordinal))
            {
                context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
                    identifier.ValueText, MessageFormatUnderscore));
                return;
            }

            string suggestion;
            if (TryGetChangedName(identifier.ValueText, out suggestion))
            {
                var messageEnding = string.Format(MessageFormatNonUnderscore, suggestion);
                context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
                    identifier.ValueText, messageEnding));
            }
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:26,代码来源:MethodName.cs

示例11: GetNameToken

            public static SyntaxToken GetNameToken(MemberDeclarationSyntax member)
            {
                if (member != null)
                {
                    switch (member.Kind())
                    {
                        case SyntaxKind.EnumDeclaration:
                            return ((EnumDeclarationSyntax)member).Identifier;
                        case SyntaxKind.ClassDeclaration:
                        case SyntaxKind.InterfaceDeclaration:
                        case SyntaxKind.StructDeclaration:
                            return ((TypeDeclarationSyntax)member).Identifier;
                        case SyntaxKind.DelegateDeclaration:
                            return ((DelegateDeclarationSyntax)member).Identifier;
                        case SyntaxKind.FieldDeclaration:
                            return ((FieldDeclarationSyntax)member).Declaration.Variables.First().Identifier;
                        case SyntaxKind.EventFieldDeclaration:
                            return ((EventFieldDeclarationSyntax)member).Declaration.Variables.First().Identifier;
                        case SyntaxKind.PropertyDeclaration:
                            return ((PropertyDeclarationSyntax)member).Identifier;
                        case SyntaxKind.EventDeclaration:
                            return ((EventDeclarationSyntax)member).Identifier;
                        case SyntaxKind.MethodDeclaration:
                            return ((MethodDeclarationSyntax)member).Identifier;
                    }
                }

                // Constructors, destructors, indexers and operators don't have names.
                return default(SyntaxToken);
            }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:30,代码来源:ImportStaticClassWithUsingCodeRefactoringProvider.cs

示例12: RemoveAllMembers

        private static MemberDeclarationSyntax RemoveAllMembers(MemberDeclarationSyntax declaration)
        {
            switch (declaration.Kind())
            {
                case SyntaxKind.EnumDeclaration:
                    return ((EnumDeclarationSyntax)declaration).WithMembers(default(SeparatedSyntaxList<EnumMemberDeclarationSyntax>));

                case SyntaxKind.StructDeclaration:
                case SyntaxKind.InterfaceDeclaration:
                case SyntaxKind.ClassDeclaration:
                    return ((TypeDeclarationSyntax)declaration).WithMembers(default(SyntaxList<MemberDeclarationSyntax>));

                default:
                    return declaration;
            }
        }
开发者ID:nemec,项目名称:roslyn,代码行数:16,代码来源:NamedTypeGenerator.cs


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