B2022-026 B2022-026 RO Memory reduction coding
This commit is contained in:
parent
d77494d6e4
commit
b8a405d173
47
PROMS/VEPROMS.CSLA.Library/EnumExtensions.cs
Normal file
47
PROMS/VEPROMS.CSLA.Library/EnumExtensions.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
// Take a flag enum and extract the cleaned string values.
|
||||
public static List<string> ToComparableStrings(this Enum eNum)
|
||||
=> eNum.ToString()
|
||||
.Split(',')
|
||||
.Select(str => str.ToCleanString())
|
||||
.ToList();
|
||||
|
||||
// Take an individual enum and report the textual value.
|
||||
public static string ToComparableString(this Enum eNum)
|
||||
=> eNum.ToString()
|
||||
.ToCleanString();
|
||||
|
||||
// Take an individual enum and report the integer values as a comma delimited string
|
||||
public static string ToCommaDelimString(this Enum eNum)
|
||||
{
|
||||
string retVal = string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(eNum.ToString()))
|
||||
{
|
||||
foreach (Enum f in Enum.GetValues(eNum.GetType()))
|
||||
{
|
||||
if (eNum.ToString().Contains(f.ToString()))
|
||||
{
|
||||
retVal = (string.IsNullOrEmpty(retVal)) ? Convert.ToInt32(f).ToString() : string.Concat(retVal, ",", Convert.ToInt32(f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Remove any spaces due to split and if `_` found change it to space.
|
||||
public static string ToCleanString(this string str)
|
||||
=> str.Replace(" ", string.Empty)
|
||||
.Replace('_', ' ');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user