/// <summary>Compares two nodes and returns a value indicating whether one is less than, equal to, or greater than the other according to StyleCop.</summary> /// <returns>A signed integer that indicates if the node should be before the other according to StyleCop.</returns> /// <param name="x">The first node to compare.</param> /// <param name="y">The second node to compare.</param> public static int Compare(IndexerDeclarationSyntax x, IndexerDeclarationSyntax y) { if (ReferenceEquals(x, y)) { return(0); } if (x is null) { return(-1); } if (y is null) { return(1); } var compare = MemberDeclarationComparer.CompareAccessibility(Accessibility(x), Accessibility(y)); if (compare != 0) { return(compare); } compare = MemberDeclarationComparer.CompareScope(x.Modifiers, y.Modifiers); if (compare != 0) { return(compare); } return(MemberDeclarationComparer.CompareSpanStart(x, y)); }
/// <summary>Compares two nodes and returns a value indicating whether one is less than, equal to, or greater than the other according to StyleCop.</summary> /// <returns>A signed integer that indicates if the node should be before the other according to StyleCop.</returns> /// <param name="x">The first node to compare.</param> /// <param name="y">The second node to compare.</param> public static int Compare(ConstructorDeclarationSyntax x, ConstructorDeclarationSyntax y) { if (ReferenceEquals(x, y)) { return(0); } if (x == null) { return(-1); } if (y == null) { return(1); } var compare = MemberDeclarationComparer.CompareScope(x.Modifiers, y.Modifiers); if (compare != 0) { return(compare); } compare = MemberDeclarationComparer.CompareAccessability(x.Modifiers, y.Modifiers, Accessibility.Private); if (compare != 0) { return(compare); } return(MemberDeclarationComparer.CompareSpanStart(x.SpanStart, y.SpanStart)); }
/// <summary>Compares two nodes and returns a value indicating whether one is less than, equal to, or greater than the other according to StyleCop.</summary> /// <returns>A signed integer that indicates if the node should be before the other according to StyleCop.</returns> /// <param name="x">The first node to compare.</param> /// <param name="y">The second node to compare.</param> public static int Compare(PropertyDeclarationSyntax x, PropertyDeclarationSyntax y) { if (ReferenceEquals(x, y)) { return(0); } if (x is null) { return(-1); } if (y is null) { return(1); } if (IsInitializedWith(x, y)) { return(1); } if (IsInitializedWith(y, x)) { return(-1); } var compare = MemberDeclarationComparer.CompareAccessibility(Accessibility(x), Accessibility(y)); if (compare != 0) { return(compare); } compare = MemberDeclarationComparer.CompareScope(x.Modifiers, y.Modifiers); if (compare != 0) { return(compare); } compare = CompareSetterAccessibility(x, y); if (compare != 0) { return(compare); } if (x.IsGetOnly()) { if (!y.IsGetOnly()) { return(-1); } } else if (y.IsGetOnly()) { return(1); } return(MemberDeclarationComparer.CompareSpanStart(x, y)); }
/// <summary>Compares two nodes and returns a value indicating whether one is less than, equal to, or greater than the other according to StyleCop.</summary> /// <returns>A signed integer that indicates if the node should be before the other according to StyleCop.</returns> /// <param name="x">The first node to compare.</param> /// <param name="y">The second node to compare.</param> public static int Compare(FieldDeclarationSyntax x, FieldDeclarationSyntax y) { if (ReferenceEquals(x, y)) { return(0); } if (x is null) { return(-1); } if (y is null) { return(1); } if (IsInitializedWith(x, y)) { return(1); } if (IsInitializedWith(y, x)) { return(-1); } var compare = MemberDeclarationComparer.CompareAccessibility(x.Modifiers, y.Modifiers, Accessibility.Private); if (compare != 0) { return(compare); } compare = MemberDeclarationComparer.CompareScope(x.Modifiers, y.Modifiers); if (compare != 0) { return(compare); } compare = CompareReadOnly(x, y); if (compare != 0) { return(compare); } compare = CompareBackingProperty(x, y); if (compare != 0) { return(compare); } return(MemberDeclarationComparer.CompareSpanStart(x, y)); }
private static int CompareSetterAccessibility(PropertyDeclarationSyntax x, PropertyDeclarationSyntax y) { if (x.TryGetSetter(out var xSetter)) { if (y.TryGetSetter(out var ySetter)) { return(MemberDeclarationComparer.CompareAccessibility( ySetter.Modifiers.Accessibility(Accessibility(y)), xSetter.Modifiers.Accessibility(Accessibility(x)))); } return(1); } return(y.TryGetSetter(out _) ? -1 : 0); }
/// <summary>Compares two nodes and returns a value indicating whether one is less than, equal to, or greater than the other according to StyleCop.</summary> /// <returns>A signed integer that indicates if the node should be before the other according to StyleCop.</returns> /// <param name="x">The first node to compare.</param> /// <param name="y">The second node to compare.</param> public static int Compare(MethodDeclarationSyntax?x, MethodDeclarationSyntax?y) { if (ReferenceEquals(x, y)) { return(0); } if (x is null) { return(-1); } if (y is null) { return(1); } if (x.Modifiers.Any(SyntaxKind.StaticKeyword) && x.Modifiers.Any(SyntaxKind.StaticKeyword) && IsInWpfContext(x) && TryGetWpfSortIndex(x, out var xIndex) && TryGetWpfSortIndex(y, out var yIndex)) { return(xIndex.CompareTo(yIndex)); } var compare = MemberDeclarationComparer.CompareAccessibility(Accessibility(x), Accessibility(y)); if (compare != 0) { return(compare); } compare = MemberDeclarationComparer.CompareScope(x.Modifiers, y.Modifiers); if (compare != 0) { return(compare); } return(MemberDeclarationComparer.CompareSpanStart(x, y));
/// <summary>Compares two nodes and returns a value indicating whether one is less than, equal to, or greater than the other according to StyleCop.</summary> /// <returns>A signed integer that indicates if the node should be before the other according to StyleCop.</returns> /// <param name="x">The first node to compare.</param> /// <param name="y">The second node to compare.</param> public static int Compare(FieldDeclarationSyntax?x, FieldDeclarationSyntax?y) { if (ReferenceEquals(x, y)) { return(0); } if (x is null) { return(-1); } if (y is null) { return(1); } if (IsInitializedWith(x, y)) { return(1); } if (IsInitializedWith(y, x)) { return(-1); } var compare = MemberDeclarationComparer.CompareAccessibility(x.Modifiers, y.Modifiers, Accessibility.Private); if (compare != 0) { if (x.Modifiers.Any(SyntaxKind.StaticKeyword) && y.Modifiers.Any(SyntaxKind.StaticKeyword)) { var byMember = CompareBackingMember(x, y); if (byMember != 0) { return(byMember); } } return(compare); } compare = MemberDeclarationComparer.CompareScope(x.Modifiers, y.Modifiers); if (compare != 0) { return(compare); } compare = CompareReadOnly(x.Modifiers, y.Modifiers); if (compare != 0) { return(compare); } compare = CompareBackingMember(x, y); if (compare != 0) { return(compare); } return(MemberDeclarationComparer.CompareSpanStart(x, y)); }