In progress
This commit is contained in:
@@ -56,7 +56,21 @@ public abstract class Enumeration : IComparable
|
||||
|
||||
public static T FromDisplayName<T>(string displayName) where T : Enumeration
|
||||
{
|
||||
var matchingItem = Parse<T, string>(displayName, "display name", item => item.Name == displayName);
|
||||
// First try exact match
|
||||
var matchingItem = GetAll<T>().FirstOrDefault(item => item.Name == displayName);
|
||||
|
||||
// If not found, try removing spaces from both the input and the enumeration names
|
||||
// This allows "InProgress" to match "In Progress", "ToDo" to match "To Do", etc.
|
||||
if (matchingItem == null)
|
||||
{
|
||||
var normalizedInput = displayName.Replace(" ", "");
|
||||
matchingItem = GetAll<T>().FirstOrDefault(item =>
|
||||
item.Name.Replace(" ", "").Equals(normalizedInput, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
if (matchingItem == null)
|
||||
throw new InvalidOperationException($"'{displayName}' is not a valid display name in {typeof(T)}");
|
||||
|
||||
return matchingItem;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user