forked from MeikelLP/quantum-core-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
117 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace QuantumCore.Extensions; | ||
|
||
public static class EnumExtensions | ||
{ | ||
public static bool TryParseEnum<TEnum>(string value, out TEnum result) where TEnum : struct, Enum | ||
{ | ||
// Check if the value is a single word | ||
if (!value.Contains('_')) | ||
{ | ||
// Capitalize the first letter and lowercase the rest to match enum naming convention | ||
var formattedSingleWord = char.ToUpper(value[0]) + value[1..].ToLower(); | ||
return Enum.TryParse(formattedSingleWord, true, out result); | ||
} | ||
|
||
// If the value contains underscores, split and format it | ||
var parts = value.ToLower().Split('_'); | ||
for (var i = 0; i < parts.Length; i++) | ||
{ | ||
parts[i] = char.ToUpper(parts[i][0]) + parts[i][1..]; | ||
} | ||
|
||
var formattedValue = string.Join("", parts); | ||
|
||
// Try to parse the formatted string as the enum type | ||
return Enum.TryParse(formattedValue, true, out 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace QuantumCore.API; | ||
|
||
public enum EPlayerClass | ||
{ | ||
Warrior = 0, | ||
Ninja = 1, | ||
Sura = 2, | ||
Shaman = 3, | ||
} |
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