/// <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; } }
private static ModifierFlags GetModifierFlags(SyntaxTokenList syntax, ElementOrderingChecks checks) { var flags = ModifierFlags.None; if (checks.Const && syntax.Any(SyntaxKind.ConstKeyword)) { flags |= ModifierFlags.Const; } else { if (checks.Static && syntax.Any(SyntaxKind.StaticKeyword)) { flags |= ModifierFlags.Static; } if (checks.Readonly && syntax.Any(SyntaxKind.ReadOnlyKeyword)) { flags |= ModifierFlags.Readonly; } } return(flags); }