From 443c03b02477a6b0dc7d2afe20f3b0fa806c5891 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 22 Dec 2023 16:05:27 +0100 Subject: [PATCH] .net 8 update --- DynamicEnums/DynamicEnum.cs | 54 ++++++++++++++++---------------- DynamicEnums/DynamicEnums.csproj | 14 ++++----- DynamicEnums/EnumHelper.cs | 8 ++--- Tests/Tests.csproj | 6 ++-- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/DynamicEnums/DynamicEnum.cs b/DynamicEnums/DynamicEnum.cs index 9017b3a..c722474 100644 --- a/DynamicEnums/DynamicEnum.cs +++ b/DynamicEnums/DynamicEnum.cs @@ -105,9 +105,9 @@ namespace DynamicEnums { /// The newly created enum value /// Thrown if the name or value passed are already present public static T Add< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(string name, BigInteger value) where T : DynamicEnum { var storage = DynamicEnum.GetStorage(typeof(T)); @@ -135,9 +135,9 @@ namespace DynamicEnums { /// The type to add this value to /// The newly created enum value public static T AddValue< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(string name) where T : DynamicEnum { BigInteger value = 0; while (DynamicEnum.IsDefined(typeof(T), value)) @@ -154,9 +154,9 @@ namespace DynamicEnums { /// The type to add this value to /// The newly created enum value public static T AddFlag< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(string name) where T : DynamicEnum { BigInteger value = 1; while (DynamicEnum.IsDefined(typeof(T), value)) @@ -207,9 +207,9 @@ namespace DynamicEnums { /// The type of enum. /// All of the unique flags that make up . public static IEnumerable GetUniqueFlags< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(T combinedFlag) where T : DynamicEnum { // we can't use the same method here as EnumHelper.GetUniqueFlags since DynamicEnum doesn't guarantee sorted values var max = DynamicEnum.GetValues().Max(DynamicEnum.GetValue); @@ -232,9 +232,9 @@ namespace DynamicEnums { /// The type of the values /// The bitwise OR (|) combination public static T Or< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(T left, T right) where T : DynamicEnum { var cache = DynamicEnum.GetStorage(typeof(T)).OrCache; if (!cache.TryGetValue((left, right), out var ret)) { @@ -252,9 +252,9 @@ namespace DynamicEnums { /// The type of the values /// The bitwise AND (&) combination public static T And< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(T left, T right) where T : DynamicEnum { var cache = DynamicEnum.GetStorage(typeof(T)).AndCache; if (!cache.TryGetValue((left, right), out var ret)) { @@ -272,9 +272,9 @@ namespace DynamicEnums { /// The type of the values /// The bitwise XOR (^) combination public static T Xor< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(T left, T right) where T : DynamicEnum { var cache = DynamicEnum.GetStorage(typeof(T)).XorCache; if (!cache.TryGetValue((left, right), out var ret)) { @@ -291,9 +291,9 @@ namespace DynamicEnums { /// The type of the values /// The bitwise NEG (~) value public static T Neg< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(T value) where T : DynamicEnum { var cache = DynamicEnum.GetStorage(typeof(T)).NegCache; if (!cache.TryGetValue(value, out var ret)) { @@ -319,9 +319,9 @@ namespace DynamicEnums { /// The type that the returned dynamic enum should have /// The defined or combined dynamic enum value public static T GetEnumValue< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(BigInteger value) where T : DynamicEnum { return (T) DynamicEnum.GetEnumValue(typeof(T), value); } @@ -333,9 +333,9 @@ namespace DynamicEnums { /// The value whose dynamic enum value to get /// The defined or combined dynamic enum value public static DynamicEnum GetEnumValue( - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif Type type, BigInteger value) { var storage = DynamicEnum.GetStorage(type); @@ -360,9 +360,9 @@ namespace DynamicEnums { /// The type of the dynamic enum value to parse /// The parsed enum value, or null if parsing fails public static T Parse< - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif T>(string strg) where T : DynamicEnum { return (T) DynamicEnum.Parse(typeof(T), strg); } @@ -376,9 +376,9 @@ namespace DynamicEnums { /// The string to parse into a dynamic enum value /// The parsed enum value, or null if parsing fails public static DynamicEnum Parse( - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif Type type, string strg) { var cache = DynamicEnum.GetStorage(type).ParseCache; if (!cache.TryGetValue(strg, out var cached)) { @@ -428,9 +428,9 @@ namespace DynamicEnums { } private static DynamicEnum Construct( - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - #endif +#endif Type type, string name, BigInteger value) { return (DynamicEnum) Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] {name, value}, CultureInfo.InvariantCulture); } @@ -457,4 +457,4 @@ namespace DynamicEnums { } } -} \ No newline at end of file +} diff --git a/DynamicEnums/DynamicEnums.csproj b/DynamicEnums/DynamicEnums.csproj index 8ff1114..55528dd 100644 --- a/DynamicEnums/DynamicEnums.csproj +++ b/DynamicEnums/DynamicEnums.csproj @@ -1,10 +1,10 @@  - net452;netstandard2.0;net6.0 + net452;netstandard2.0;net8.0 true - true + true - + Ellpeck Enum-like single-instance values with additional capabilities, including dynamic addition of new arbitrary values and flags @@ -15,13 +15,13 @@ README.md 1.0.1 - + - - + + - \ No newline at end of file + diff --git a/DynamicEnums/EnumHelper.cs b/DynamicEnums/EnumHelper.cs index 83e43e7..2da36f6 100644 --- a/DynamicEnums/EnumHelper.cs +++ b/DynamicEnums/EnumHelper.cs @@ -14,11 +14,11 @@ namespace DynamicEnums { /// The type whose enum to get /// An enumerable of the values of the enum, in declaration order. public static T[] GetValues() where T : struct, Enum { - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER return Enum.GetValues(); - #else +#else return (T[]) Enum.GetValues(typeof(T)); - #endif +#endif } /// @@ -79,4 +79,4 @@ namespace DynamicEnums { } } -} \ No newline at end of file +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index d87f80b..91dba12 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -1,10 +1,10 @@ - net6.0 + net8.0 nunit false - + @@ -13,7 +13,7 @@ - +