Refactor enum handling in MemoryCache and HistoryController
Updated `GetEnumAsDictionary<TEnum>` in `MemoryCacheExtensions.cs` to use a loop for populating a dictionary of enum values, removing LINQ for simplicity. Modified `HistoryController.cs` to adjust method signatures for `GetReferenceTypes` and `GetEnvelopeStatus`, allowing optional parameters for better conditional responses. Added necessary using directives.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System;
|
||||
|
||||
namespace EnvelopeGenerator.Extensions;
|
||||
|
||||
@@ -7,15 +8,13 @@ public static class MemoryCacheExtensions
|
||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache)
|
||||
where TEnum : Enum
|
||||
{
|
||||
var referenceTypes = Enum.GetValues(typeof(TEnum))
|
||||
.Cast<TEnum>()
|
||||
.ToDictionary(rt =>
|
||||
{
|
||||
var key = rt.ToString();
|
||||
var keyAsCamelCase = char.ToLowerInvariant(key[0]) + key[1..];
|
||||
return keyAsCamelCase;
|
||||
}, rt => Convert.ToInt32(rt));
|
||||
var dict = new Dictionary<string, int>();
|
||||
|
||||
return referenceTypes;
|
||||
foreach (TEnum role in Enum.GetValues(typeof(TEnum)))
|
||||
{
|
||||
dict[role.ToString()] = Convert.ToInt32(role);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user