11using System ;
2+ using System . Linq ;
23using System . Windows . Markup ;
34
45namespace EQTool . Services . MarkupExtensions
@@ -12,6 +13,12 @@ public EnumBindingSourceExtension(Type enumType)
1213 {
1314 EnumType = enumType ;
1415 }
16+
17+ /// <summary>
18+ /// Comma-separated list of enum names to exclude
19+ /// e.g. "BySpellExceptYou,SomethingElse"
20+ /// </summary>
21+ public string Exclude { get ; set ; }
1522
1623 private Type _EnumType ;
1724 public Type EnumType
@@ -20,11 +27,9 @@ public Type EnumType
2027 set
2128 {
2229 if ( value == _EnumType )
23- {
2430 return ;
25- }
2631
27- if ( null != value )
32+ if ( value != null )
2833 {
2934 var enumType = Nullable . GetUnderlyingType ( value ) ?? value ;
3035 if ( ! enumType . IsEnum )
@@ -39,20 +44,35 @@ public Type EnumType
3944
4045 public override object ProvideValue ( IServiceProvider serviceProvider )
4146 {
42- if ( null == _EnumType )
47+ if ( _EnumType == null )
4348 {
4449 throw new InvalidOperationException ( "The EnumType must be specified." ) ;
4550 }
4651
4752 var actualEnumType = Nullable . GetUnderlyingType ( _EnumType ) ?? _EnumType ;
48- var enumValues = Enum . GetValues ( actualEnumType ) ;
49- if ( actualEnumType == _EnumType )
53+ var enumValues = Enum . GetValues ( actualEnumType ) . Cast < object > ( ) ;
54+
55+ // Handle exclusions
56+ if ( ! string . IsNullOrWhiteSpace ( Exclude ) )
5057 {
51- return enumValues ;
58+ var excludedNames = Exclude
59+ . Split ( ',' )
60+ . Select ( s => s . Trim ( ) )
61+ . Where ( s => ! string . IsNullOrEmpty ( s ) )
62+ . ToHashSet ( StringComparer . OrdinalIgnoreCase ) ;
63+
64+ enumValues = enumValues
65+ . Where ( v => ! excludedNames . Contains ( v . ToString ( ) ) ) ;
5266 }
5367
54- var tempArray = Array . CreateInstance ( actualEnumType , enumValues . Length + 1 ) ;
55- enumValues . CopyTo ( tempArray , 1 ) ;
68+ var final = enumValues . ToArray ( ) ;
69+
70+ // Nullable enum support
71+ if ( actualEnumType == _EnumType )
72+ return final ;
73+
74+ var tempArray = Array . CreateInstance ( actualEnumType , final . Length + 1 ) ;
75+ final . CopyTo ( tempArray , 1 ) ;
5676 return tempArray ;
5777 }
5878 }
0 commit comments