In progress
Some checks failed
Code Coverage / Generate Coverage Report (push) Has been cancelled
Tests / Run Tests (9.0.x) (push) Has been cancelled
Tests / Docker Build Test (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled

This commit is contained in:
Yaojia Wang
2025-11-03 11:51:02 +01:00
parent 24fb646739
commit fe8ad1c1f9
101 changed files with 26471 additions and 250 deletions

View File

@@ -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;
}