mirror of
https://github.com/Ellpeck/DynamicEnums.git
synced 2024-11-24 01:18:35 +01:00
use a comma as the dynamic enum delimiter to be in line with regular enums
This commit is contained in:
parent
1fe7725ca9
commit
23e94fa6f5
4 changed files with 9 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ obj
|
|||
packages
|
||||
*.nupkg
|
||||
TestResults
|
||||
*.DotSettings.user
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace DynamicEnums {
|
|||
var otherValue = DynamicEnum.GetValue(other);
|
||||
if (otherValue != 0) {
|
||||
if (included.Length > 0)
|
||||
included.Append(" | ");
|
||||
included.Append(", ");
|
||||
included.Append(other);
|
||||
remain &= ~otherValue;
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ namespace DynamicEnums {
|
|||
var cache = DynamicEnum.GetStorage(type).ParseCache;
|
||||
if (!cache.TryGetValue(strg, out var cached)) {
|
||||
BigInteger? accum = null;
|
||||
foreach (var val in strg.Split('|')) {
|
||||
foreach (var val in strg.Split(',')) {
|
||||
foreach (var defined in DynamicEnum.GetValues(type)) {
|
||||
if (defined.name == val.Trim()) {
|
||||
accum = (accum ?? 0) | DynamicEnum.GetValue(defined);
|
||||
|
|
|
@ -48,11 +48,11 @@ bool hasAll = allFlags1.HasAllFlags(MyEnum.FlagOne | MyEnum.ValueOne); // false
|
|||
|
||||
// displaying a dynamic enum value or flag
|
||||
Console.WriteLine(MyEnum.FlagOne); // "FlagOne"
|
||||
Console.WriteLine(allFlags1); // "FlagOne | FlagTwo | FlagThree"
|
||||
Console.WriteLine(allFlags1); // "FlagOne, FlagTwo, FlagThree"
|
||||
|
||||
// parsing a dynamic enum value
|
||||
MyEnum parsed1 = DynamicEnum.Parse<MyEnum>("FlagOne");
|
||||
MyEnum parsed2 = DynamicEnum.Parse<MyEnum>("FlagOne | FlagThree");
|
||||
MyEnum parsed2 = DynamicEnum.Parse<MyEnum>("FlagOne, FlagThree");
|
||||
```
|
||||
|
||||
You can also check out [the tests](https://github.com/Ellpeck/DynamicEnums/tree/main/Tests) for some more complex examples.
|
||||
|
|
|
@ -74,13 +74,13 @@ public class EnumTests {
|
|||
Assert.AreEqual(flags[24].HasAnyFlags(DynamicEnum.GetEnumValue<TestDynamicEnum>(0)), false);
|
||||
|
||||
Assert.AreEqual(DynamicEnum.Parse<TestDynamicEnum>("Flag24"), flags[24]);
|
||||
Assert.AreEqual(DynamicEnum.Parse<TestDynamicEnum>("Flag24 | Flag43"), DynamicEnum.Or(flags[24], flags[43]));
|
||||
Assert.AreEqual(DynamicEnum.Parse<TestDynamicEnum>("Flag24, Flag43"), DynamicEnum.Or(flags[24], flags[43]));
|
||||
|
||||
Assert.AreEqual(flags[24].ToString(), "Flag24");
|
||||
Assert.AreEqual(zero.ToString(), "Zero");
|
||||
Assert.AreEqual(DynamicEnum.GetEnumValue<TestDynamicEnum>(0).ToString(), "Zero");
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], flags[43]).ToString(), "Flag24 | Flag43");
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], DynamicEnum.GetEnumValue<TestDynamicEnum>(new BigInteger(1) << 99)).ToString(), "Flag24 | Flag99");
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], flags[43]).ToString(), "Flag24, Flag43");
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], DynamicEnum.GetEnumValue<TestDynamicEnum>(new BigInteger(1) << 99)).ToString(), "Flag24, Flag99");
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], DynamicEnum.GetEnumValue<TestDynamicEnum>(new BigInteger(1) << 101)).ToString(), (DynamicEnum.GetValue(flags[24]) | new BigInteger(1) << 101).ToString());
|
||||
|
||||
Assert.True(DynamicEnum.IsDefined(flags[27]));
|
||||
|
|
Loading…
Reference in a new issue