57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
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)
 | 
						|
        {
 | 
						|
            string retval = str;
 | 
						|
            // B2022-114: ROs not printing in Word docs.  spaces were removed, but this should only happen in unit designators such
 | 
						|
            //  as <U-OTHER NAME>.  Keep the code that replaces the '_' with a space.
 | 
						|
            if (retval.ToUpper().StartsWith("<U-"))
 | 
						|
            {
 | 
						|
                retval = retval.Replace(" ", string.Empty);
 | 
						|
            }
 | 
						|
            retval = retval.Replace('_', ' ');
 | 
						|
            return retval;
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |