mirror of
https://github.com/Ellpeck/DynamicEnums.git
synced 2024-11-24 01:18:35 +01:00
.net 8 update
This commit is contained in:
parent
94b6304d52
commit
443c03b024
4 changed files with 41 additions and 41 deletions
|
@ -105,9 +105,9 @@ namespace DynamicEnums {
|
||||||
/// <returns>The newly created enum value</returns>
|
/// <returns>The newly created enum value</returns>
|
||||||
/// <exception cref="ArgumentException">Thrown if the name or value passed are already present</exception>
|
/// <exception cref="ArgumentException">Thrown if the name or value passed are already present</exception>
|
||||||
public static T Add<
|
public static T Add<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(string name, BigInteger value) where T : DynamicEnum {
|
T>(string name, BigInteger value) where T : DynamicEnum {
|
||||||
var storage = DynamicEnum.GetStorage(typeof(T));
|
var storage = DynamicEnum.GetStorage(typeof(T));
|
||||||
|
|
||||||
|
@ -135,9 +135,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type to add this value to</typeparam>
|
/// <typeparam name="T">The type to add this value to</typeparam>
|
||||||
/// <returns>The newly created enum value</returns>
|
/// <returns>The newly created enum value</returns>
|
||||||
public static T AddValue<
|
public static T AddValue<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(string name) where T : DynamicEnum {
|
T>(string name) where T : DynamicEnum {
|
||||||
BigInteger value = 0;
|
BigInteger value = 0;
|
||||||
while (DynamicEnum.IsDefined(typeof(T), value))
|
while (DynamicEnum.IsDefined(typeof(T), value))
|
||||||
|
@ -154,9 +154,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type to add this value to</typeparam>
|
/// <typeparam name="T">The type to add this value to</typeparam>
|
||||||
/// <returns>The newly created enum value</returns>
|
/// <returns>The newly created enum value</returns>
|
||||||
public static T AddFlag<
|
public static T AddFlag<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(string name) where T : DynamicEnum {
|
T>(string name) where T : DynamicEnum {
|
||||||
BigInteger value = 1;
|
BigInteger value = 1;
|
||||||
while (DynamicEnum.IsDefined(typeof(T), value))
|
while (DynamicEnum.IsDefined(typeof(T), value))
|
||||||
|
@ -207,9 +207,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type of enum.</typeparam>
|
/// <typeparam name="T">The type of enum.</typeparam>
|
||||||
/// <returns>All of the unique flags that make up <paramref name="combinedFlag"/>.</returns>
|
/// <returns>All of the unique flags that make up <paramref name="combinedFlag"/>.</returns>
|
||||||
public static IEnumerable<T> GetUniqueFlags<
|
public static IEnumerable<T> GetUniqueFlags<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(T combinedFlag) where T : DynamicEnum {
|
T>(T combinedFlag) where T : DynamicEnum {
|
||||||
// we can't use the same method here as EnumHelper.GetUniqueFlags since DynamicEnum doesn't guarantee sorted values
|
// we can't use the same method here as EnumHelper.GetUniqueFlags since DynamicEnum doesn't guarantee sorted values
|
||||||
var max = DynamicEnum.GetValues<T>().Max(DynamicEnum.GetValue);
|
var max = DynamicEnum.GetValues<T>().Max(DynamicEnum.GetValue);
|
||||||
|
@ -232,9 +232,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type of the values</typeparam>
|
/// <typeparam name="T">The type of the values</typeparam>
|
||||||
/// <returns>The bitwise OR (|) combination</returns>
|
/// <returns>The bitwise OR (|) combination</returns>
|
||||||
public static T Or<
|
public static T Or<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(T left, T right) where T : DynamicEnum {
|
T>(T left, T right) where T : DynamicEnum {
|
||||||
var cache = DynamicEnum.GetStorage(typeof(T)).OrCache;
|
var cache = DynamicEnum.GetStorage(typeof(T)).OrCache;
|
||||||
if (!cache.TryGetValue((left, right), out var ret)) {
|
if (!cache.TryGetValue((left, right), out var ret)) {
|
||||||
|
@ -252,9 +252,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type of the values</typeparam>
|
/// <typeparam name="T">The type of the values</typeparam>
|
||||||
/// <returns>The bitwise AND (&) combination</returns>
|
/// <returns>The bitwise AND (&) combination</returns>
|
||||||
public static T And<
|
public static T And<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(T left, T right) where T : DynamicEnum {
|
T>(T left, T right) where T : DynamicEnum {
|
||||||
var cache = DynamicEnum.GetStorage(typeof(T)).AndCache;
|
var cache = DynamicEnum.GetStorage(typeof(T)).AndCache;
|
||||||
if (!cache.TryGetValue((left, right), out var ret)) {
|
if (!cache.TryGetValue((left, right), out var ret)) {
|
||||||
|
@ -272,9 +272,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type of the values</typeparam>
|
/// <typeparam name="T">The type of the values</typeparam>
|
||||||
/// <returns>The bitwise XOR (^) combination</returns>
|
/// <returns>The bitwise XOR (^) combination</returns>
|
||||||
public static T Xor<
|
public static T Xor<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(T left, T right) where T : DynamicEnum {
|
T>(T left, T right) where T : DynamicEnum {
|
||||||
var cache = DynamicEnum.GetStorage(typeof(T)).XorCache;
|
var cache = DynamicEnum.GetStorage(typeof(T)).XorCache;
|
||||||
if (!cache.TryGetValue((left, right), out var ret)) {
|
if (!cache.TryGetValue((left, right), out var ret)) {
|
||||||
|
@ -291,9 +291,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type of the values</typeparam>
|
/// <typeparam name="T">The type of the values</typeparam>
|
||||||
/// <returns>The bitwise NEG (~) value</returns>
|
/// <returns>The bitwise NEG (~) value</returns>
|
||||||
public static T Neg<
|
public static T Neg<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(T value) where T : DynamicEnum {
|
T>(T value) where T : DynamicEnum {
|
||||||
var cache = DynamicEnum.GetStorage(typeof(T)).NegCache;
|
var cache = DynamicEnum.GetStorage(typeof(T)).NegCache;
|
||||||
if (!cache.TryGetValue(value, out var ret)) {
|
if (!cache.TryGetValue(value, out var ret)) {
|
||||||
|
@ -319,9 +319,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type that the returned dynamic enum should have</typeparam>
|
/// <typeparam name="T">The type that the returned dynamic enum should have</typeparam>
|
||||||
/// <returns>The defined or combined dynamic enum value</returns>
|
/// <returns>The defined or combined dynamic enum value</returns>
|
||||||
public static T GetEnumValue<
|
public static T GetEnumValue<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(BigInteger value) where T : DynamicEnum {
|
T>(BigInteger value) where T : DynamicEnum {
|
||||||
return (T) DynamicEnum.GetEnumValue(typeof(T), value);
|
return (T) DynamicEnum.GetEnumValue(typeof(T), value);
|
||||||
}
|
}
|
||||||
|
@ -333,9 +333,9 @@ namespace DynamicEnums {
|
||||||
/// <param name="value">The value whose dynamic enum value to get</param>
|
/// <param name="value">The value whose dynamic enum value to get</param>
|
||||||
/// <returns>The defined or combined dynamic enum value</returns>
|
/// <returns>The defined or combined dynamic enum value</returns>
|
||||||
public static DynamicEnum GetEnumValue(
|
public static DynamicEnum GetEnumValue(
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
Type type, BigInteger value) {
|
Type type, BigInteger value) {
|
||||||
var storage = DynamicEnum.GetStorage(type);
|
var storage = DynamicEnum.GetStorage(type);
|
||||||
|
|
||||||
|
@ -360,9 +360,9 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type of the dynamic enum value to parse</typeparam>
|
/// <typeparam name="T">The type of the dynamic enum value to parse</typeparam>
|
||||||
/// <returns>The parsed enum value, or null if parsing fails</returns>
|
/// <returns>The parsed enum value, or null if parsing fails</returns>
|
||||||
public static T Parse<
|
public static T Parse<
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
T>(string strg) where T : DynamicEnum {
|
T>(string strg) where T : DynamicEnum {
|
||||||
return (T) DynamicEnum.Parse(typeof(T), strg);
|
return (T) DynamicEnum.Parse(typeof(T), strg);
|
||||||
}
|
}
|
||||||
|
@ -376,9 +376,9 @@ namespace DynamicEnums {
|
||||||
/// <param name="strg">The string to parse into a dynamic enum value</param>
|
/// <param name="strg">The string to parse into a dynamic enum value</param>
|
||||||
/// <returns>The parsed enum value, or null if parsing fails</returns>
|
/// <returns>The parsed enum value, or null if parsing fails</returns>
|
||||||
public static DynamicEnum Parse(
|
public static DynamicEnum Parse(
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
Type type, string strg) {
|
Type type, string strg) {
|
||||||
var cache = DynamicEnum.GetStorage(type).ParseCache;
|
var cache = DynamicEnum.GetStorage(type).ParseCache;
|
||||||
if (!cache.TryGetValue(strg, out var cached)) {
|
if (!cache.TryGetValue(strg, out var cached)) {
|
||||||
|
@ -428,9 +428,9 @@ namespace DynamicEnums {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DynamicEnum Construct(
|
private static DynamicEnum Construct(
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
|
||||||
#endif
|
#endif
|
||||||
Type type, string name, BigInteger value) {
|
Type type, string name, BigInteger value) {
|
||||||
return (DynamicEnum) Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] {name, value}, CultureInfo.InvariantCulture);
|
return (DynamicEnum) Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] {name, value}, CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
@ -457,4 +457,4 @@ namespace DynamicEnums {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net452;netstandard2.0;net6.0</TargetFrameworks>
|
<TargetFrameworks>net452;netstandard2.0;net8.0</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<IsTrimmable>true</IsTrimmable>
|
<IsAotCompatible Condition="'$(TargetFramework)'=='net8.0'">true</IsAotCompatible>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors>Ellpeck</Authors>
|
<Authors>Ellpeck</Authors>
|
||||||
<Description>Enum-like single-instance values with additional capabilities, including dynamic addition of new arbitrary values and flags</Description>
|
<Description>Enum-like single-instance values with additional capabilities, including dynamic addition of new arbitrary values and flags</Description>
|
||||||
|
@ -15,13 +15,13 @@
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<VersionPrefix>1.0.1</VersionPrefix>
|
<VersionPrefix>1.0.1</VersionPrefix>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" Condition="'$(TargetFramework)'=='net452'" />
|
<PackageReference Include="System.ValueTuple" Version="4.5.0" Condition="'$(TargetFramework)'=='net452'" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="../README.md" Pack="true" PackagePath="" />
|
<None Include="../README.md" Pack="true" PackagePath="" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -14,11 +14,11 @@ namespace DynamicEnums {
|
||||||
/// <typeparam name="T">The type whose enum to get</typeparam>
|
/// <typeparam name="T">The type whose enum to get</typeparam>
|
||||||
/// <returns>An enumerable of the values of the enum, in declaration order.</returns>
|
/// <returns>An enumerable of the values of the enum, in declaration order.</returns>
|
||||||
public static T[] GetValues<T>() where T : struct, Enum {
|
public static T[] GetValues<T>() where T : struct, Enum {
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
return Enum.GetValues<T>();
|
return Enum.GetValues<T>();
|
||||||
#else
|
#else
|
||||||
return (T[]) Enum.GetValues(typeof(T));
|
return (T[]) Enum.GetValues(typeof(T));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -79,4 +79,4 @@ namespace DynamicEnums {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<VSTestLogger>nunit</VSTestLogger>
|
<VSTestLogger>nunit</VSTestLogger>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||||
<PackageReference Include="NunitXml.TestLogger" Version="3.0.117" />
|
<PackageReference Include="NunitXml.TestLogger" Version="3.0.117" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DynamicEnums\DynamicEnums.csproj" />
|
<ProjectReference Include="..\DynamicEnums\DynamicEnums.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
Loading…
Reference in a new issue