Compare commits

...

8 commits

Author SHA1 Message Date
Ell
eb2c87a462 use quotes when publishing 2024-02-04 11:11:23 +01:00
Ell
be8a4b4f41 1.2.0 2024-02-04 11:10:05 +01:00
Ell
4eb15ccae2 actually don't skip duplicates 2024-02-04 11:09:45 +01:00
Ell
ffbd154153 pass defined as a constructor argument 2024-02-04 11:09:13 +01:00
Ell
5146f7d8a8 skip duplicates 2024-02-04 11:08:33 +01:00
Ell
ab37d8fc18 help 2024-02-04 11:04:57 +01:00
Ell
a5616b6873 maybe use quotes? 2024-02-04 11:01:07 +01:00
Ell
9330354a2a use github actions 2024-02-04 10:57:40 +01:00
5 changed files with 31 additions and 28 deletions

22
.github/workflows/main.yml vendored Normal file
View file

@ -0,0 +1,22 @@
on: [push, pull_request]
jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Build
run: dotnet build
- name: Test
run: dotnet test --collect:"XPlat Code Coverage"
- name: Pack
run: dotnet pack --version-suffix ci.$GITHUB_RUN_NUMBER
- name: Publish
if: github.event_name == 'push' && github.ref_name == 'main'
run: dotnet nuget push -s https://nuget.ellpeck.de/v3/index.json **/*.nupkg -k '${{ secrets.BAGET_KEY }}' -n

View file

@ -1,20 +0,0 @@
variables:
- &image mcr.microsoft.com/dotnet/sdk:8.0-jammy
steps:
build:
image: *image
commands: dotnet build
test:
image: *image
commands: dotnet test --collect:"XPlat Code Coverage"
pack:
image: *image
commands: dotnet pack --version-suffix ci.$CI_PIPELINE_NUMBER
publish:
image: *image
when:
branch: main
event: push
commands: dotnet nuget push -s https://nuget.ellpeck.de/v3/index.json **/*.nupkg -k $BAGET_KEY -n
secrets:
- baget_key

View file

@ -42,7 +42,8 @@ namespace DynamicEnums {
/// </summary> /// </summary>
/// <param name="name">The name of the enum value</param> /// <param name="name">The name of the enum value</param>
/// <param name="value">The value</param> /// <param name="value">The value</param>
protected DynamicEnum(string name, BigInteger value) { /// <param name="defined">Whether this enum value <see cref="IsDefined(DynamicEnum)"/>, and thus, not a combined flag.</param>
protected DynamicEnum(string name, BigInteger value, bool defined) {
this.value = value; this.value = value;
this.name = name; this.name = name;
} }
@ -121,7 +122,7 @@ namespace DynamicEnums {
throw new ArgumentException($"Duplicate name {name}", nameof(name)); throw new ArgumentException($"Duplicate name {name}", nameof(name));
} }
var ret = DynamicEnum.Construct(typeof(T), name, value); var ret = DynamicEnum.Construct(typeof(T), name, value, true);
storage.Values.Add(value, ret); storage.Values.Add(value, ret);
return (T) ret; return (T) ret;
} }
@ -345,7 +346,7 @@ namespace DynamicEnums {
// otherwise, cache the combined value // otherwise, cache the combined value
if (!storage.FlagCache.TryGetValue(value, out var combined)) { if (!storage.FlagCache.TryGetValue(value, out var combined)) {
combined = DynamicEnum.Construct(type, null, value); combined = DynamicEnum.Construct(type, null, value, false);
storage.FlagCache.Add(value, combined); storage.FlagCache.Add(value, combined);
} }
return combined; return combined;
@ -431,8 +432,8 @@ namespace DynamicEnums {
#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, bool defined) {
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, defined}, CultureInfo.InvariantCulture);
} }
private class Storage { private class Storage {
@ -457,4 +458,4 @@ namespace DynamicEnums {
} }
} }
} }

View file

@ -13,7 +13,7 @@
<RepositoryUrl>https://github.com/Ellpeck/DynamicEnums</RepositoryUrl> <RepositoryUrl>https://github.com/Ellpeck/DynamicEnums</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
<VersionPrefix>1.1.0</VersionPrefix> <VersionPrefix>1.2.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -86,7 +86,7 @@ public class EnumTests {
private class TestDynamicEnum : DynamicEnum { private class TestDynamicEnum : DynamicEnum {
public TestDynamicEnum(string name, BigInteger value) : base(name, value) {} public TestDynamicEnum(string name, BigInteger value, bool defined) : base(name, value, defined) {}
} }