@@ -131,7 +131,8 @@ private static ImmutableArray<EnumField> GetEnumFields(SourceProductionContext s
131
131
var key = keyAttr ? . ConstructorArguments . FirstOrDefault ( ) . Value ? . ToString ( ) ?? string . Empty ;
132
132
var value = valueAttr ? . ConstructorArguments . FirstOrDefault ( ) . Value ? . ToString ( ) ?? string . Empty ;
133
133
134
- if ( keyAttrExist && ! string . IsNullOrEmpty ( key ) )
134
+ // Users may use " " as a key, so we need to check if the key is not empty and not whitespace
135
+ if ( keyAttrExist && ! string . IsNullOrWhiteSpace ( key ) )
135
136
{
136
137
// If localization key exists and is valid, use it
137
138
enumFields . Add ( new EnumField ( enumFieldName , key , valueAttrExist ? value : null ) ) ;
@@ -316,7 +317,8 @@ private static void GenerateUpdateLabelsMethod(
316
317
sb . AppendLine ( $ "{ tabString } {{") ;
317
318
sb . AppendLine ( $ "{ tabString } { tabString } foreach (var item in options)") ;
318
319
sb . AppendLine ( $ "{ tabString } { tabString } {{") ;
319
- sb . AppendLine ( $ "{ tabString } { tabString } { tabString } if (!string.IsNullOrEmpty(item.LocalizationKey))") ;
320
+ // Users may use " " as a key, so we need to check if the key is not empty and not whitespace
321
+ sb . AppendLine ( $ "{ tabString } { tabString } { tabString } if (!string.IsNullOrWhiteSpace(item.LocalizationKey))") ;
320
322
sb . AppendLine ( $ "{ tabString } { tabString } { tabString } {{") ;
321
323
sb . AppendLine ( $ "{ tabString } { tabString } { tabString } { tabString } item.Display = { getTranslation } (item.LocalizationKey);") ;
322
324
sb . AppendLine ( $ "{ tabString } { tabString } { tabString } }}") ;
@@ -334,7 +336,8 @@ public class EnumField
334
336
public string LocalizationKey { get ; set ; }
335
337
public string LocalizationValue { get ; set ; }
336
338
337
- public bool UseLocalizationKey => LocalizationKey != null ;
339
+ // Users may use " " as a key, so we need to check if the key is not empty and not whitespace
340
+ public bool UseLocalizationKey => ! string . IsNullOrWhiteSpace ( LocalizationKey ) ;
338
341
339
342
public EnumField ( string enumFieldName , string localizationValue ) : this ( enumFieldName , null , localizationValue )
340
343
{
0 commit comments