File tree Expand file tree Collapse file tree
Runtime/Attributes/Regular Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ private void UpdateConstraint(TypeConstraintAttribute attribute)
5353 sharedConstraint . ApplyTarget ( attribute . AssemblyType ) ;
5454 if ( sharedConstraint is TypeConstraintStandard constraint )
5555 {
56+ constraint . IsOrdered = attribute . OrderTypes ;
5657 constraint . AllowAbstract = attribute . AllowAbstract ;
5758 constraint . AllowObsolete = attribute . AllowObsolete ;
5859 constraint . Settings = attribute . TypeSettings ;
Original file line number Diff line number Diff line change @@ -32,16 +32,21 @@ public virtual void ApplyTarget(Type type)
3232
3333 public override bool Equals ( object obj )
3434 {
35- return obj is TypeConstraintContext constraint &&
36- EqualityComparer < Type > . Default . Equals ( targetType , constraint . targetType ) ;
35+ return obj is TypeConstraintContext context &&
36+ EqualityComparer < Type > . Default . Equals ( TargetType , context . TargetType ) &&
37+ IsOrdered == context . IsOrdered ;
3738 }
3839
3940 public override int GetHashCode ( )
4041 {
41- return 1673078848 + EqualityComparer < Type > . Default . GetHashCode ( targetType ) ;
42+ var hashCode = - 509589530 ;
43+ hashCode = hashCode * - 1521134295 + EqualityComparer < Type > . Default . GetHashCode ( TargetType ) ;
44+ hashCode = hashCode * - 1521134295 + IsOrdered . GetHashCode ( ) ;
45+ return hashCode ;
4246 }
4347
4448
4549 public Type TargetType => targetType ;
50+ public bool IsOrdered { get ; set ; } = true ;
4651 }
4752}
Original file line number Diff line number Diff line change @@ -106,6 +106,11 @@ public static List<Type> FindTypes(TypeConstraintContext constraint)
106106
107107 typesList . Sort ( ( a , b ) => a . FullName . CompareTo ( b . FullName ) ) ;
108108#endif
109+ if ( constraint . IsOrdered )
110+ {
111+ typesList . Sort ( ( t1 , t2 ) => t1 . Name . CompareTo ( t2 . Name ) ) ;
112+ }
113+
109114 return typesList ;
110115 }
111116
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ public TypeConstraintAttribute(Type assemblyType)
3939 /// </summary>
4040 public bool AddTextSearchField { get ; set ; }
4141
42+ /// <summary>
43+ /// Indicates if types should be sorted alphabetically.
44+ /// </summary>
45+ public bool OrderTypes { get ; set ; } = true ;
46+
4247 /// <summary>
4348 /// Gets or sets grouping of selectable classes.
4449 /// Defaults to <see cref="ClassGrouping.None"/> unless explicitly specified.
You can’t perform that action at this time.
0 commit comments