-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
394 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,5 +40,7 @@ public enum PayrunEventTypeEnum | |
|
||
Archived = 10, | ||
|
||
Unarchived = 11 | ||
Unarchived = 11, | ||
|
||
Cancelled = 12, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//----------------------------------------------------------------------------- | ||
// Filename: GuidExtensions.cs | ||
// | ||
// Description: Contains extension methods for Guid types: | ||
// | ||
// Author(s): | ||
// Aaron Clauson ([email protected]) | ||
// | ||
// History: | ||
// 15 Oct 2024 Aaron Clauson Created, Carne, Wexford, Ireland. | ||
// | ||
// License: | ||
// Proprietary NoFrixion. | ||
//----------------------------------------------------------------------------- | ||
|
||
namespace NoFrixion.MoneyMoov; | ||
|
||
public static class EnumExtensions | ||
{ | ||
/// <summary> | ||
/// This method converts an Enum with the Flags attribute to a list of Enums. | ||
/// </summary> | ||
public static List<T> ToList<T>(this T flags) where T : Enum | ||
{ | ||
if (!typeof(T).IsDefined(typeof(FlagsAttribute), false)) | ||
{ | ||
throw new ArgumentException("The type parameter T must have the Flags attribute.", nameof(flags)); | ||
} | ||
|
||
// Check if the enum underlying type is ulong | ||
var underlyingType = Enum.GetUnderlyingType(typeof(T)); | ||
|
||
if (underlyingType == typeof(ulong)) | ||
{ | ||
return Enum.GetValues(typeof(T)) | ||
.Cast<T>() | ||
.Where(value => flags.HasFlag(value) && Convert.ToUInt64(value) != 0) // Exclude None or 0 | ||
.ToList(); | ||
} | ||
else | ||
{ | ||
return Enum.GetValues(typeof(T)) | ||
.Cast<T>() | ||
.Where(value => flags.HasFlag(value) && Convert.ToInt32(value) != 0) // Exclude None or 0 | ||
.ToList(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// This method converts list of flag enum values to a single flag enum. | ||
/// </summary> | ||
public static T ToFlagEnum<T>(this IEnumerable<T> enumValues) where T : Enum | ||
{ | ||
if (!typeof(T).IsDefined(typeof(FlagsAttribute), false)) | ||
{ | ||
throw new ArgumentException("The type parameter T must have the Flags attribute.", nameof(enumValues)); | ||
} | ||
|
||
// Check if the enum underlying type is ulong | ||
var underlyingType = Enum.GetUnderlyingType(typeof(T)); | ||
|
||
if (underlyingType == typeof(ulong)) | ||
{ | ||
ulong result = 0UL; | ||
|
||
foreach (var value in enumValues) | ||
{ | ||
result |= Convert.ToUInt64(value); | ||
} | ||
|
||
return (T)Enum.ToObject(typeof(T), result); | ||
} | ||
else | ||
{ | ||
int result = 0; | ||
|
||
foreach (var value in enumValues) | ||
{ | ||
result |= Convert.ToInt32(value); | ||
} | ||
|
||
return (T)Enum.ToObject(typeof(T), result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.