Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.5.2] - 2026-01-29

### Fixed

- StrongTypedEnum allowed numbers as string in its constructor, thereby storing the value internally as e.g. "0". This in turn would be the value used in serialization, which could cause problems downstream.
- The fix ensures the internal string representation is always the enum's name, not the number.

## [2.5.1] - 2025-10-15

### Added
Expand Down
12 changes: 11 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<!-- Directory.Build.props -->
<Project>
<PropertyGroup>
<Version>2.5.1</Version>
<Version>2.5.2</Version>

<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Copyright>Steffen Skov 2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
</Project>

1 change: 1 addition & 0 deletions StrongTypedId.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_items", "_items", "{22179B
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
CHANGELOG.md = CHANGELOG.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{24F40718-A883-432A-934A-BF4C5D85874A}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Description>TypeConverter extension for easy usage of StrongTypedId with the Dapper.DDD.Repository.</Description>
<Copyright>Steffen Skov 2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/steffenskov/StrongTypedId</PackageProjectUrl>
<PackageTags>strongly-typed, Id, Dapper</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Description>EntityFrame.Core ValueConverter for the StrongTypedId library</Description>
<Copyright>Steffen Skov 2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/steffenskov/StrongTypedId</PackageProjectUrl>
<PackageTags>strongly-typed, Id, EF, EntityFramework</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
9 changes: 0 additions & 9 deletions src/StrongTypedId.LiteDB/StrongTypedId.LiteDB.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Description>Serialization extension for easy usage of StrongTypedId with LiteDB.</Description>
<Copyright>Steffen Skov 2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/steffenskov/StrongTypedId</PackageProjectUrl>
<PackageTags>strongly-typed, Id, litedb, litedatabase</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
19 changes: 5 additions & 14 deletions src/StrongTypedId.MongoDB/StrongTypedId.MongoDB.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Description>Serialization extension for easy usage of StrongTypedId with MongoDB.</Description>
<Copyright>Steffen Skov 2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/steffenskov/StrongTypedId</PackageProjectUrl>
<PackageTags>strongly-typed, Id, mongodb, mongo</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<NoWarn>$(NoWarn);NU1504;NU1008</NoWarn>

</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StrongTypedId\StrongTypedId.csproj" />
<ProjectReference Include="..\StrongTypedId\StrongTypedId.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" />
<PackageReference Include="Ckode.ServiceLocator" />
<PackageReference Include="MongoDB.Driver"/>
<PackageReference Include="Ckode.ServiceLocator"/>
</ItemGroup>

</Project>
9 changes: 0 additions & 9 deletions src/StrongTypedId.NewtonSoft/StrongTypedId.NewtonSoft.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Description>NewtonSoft.Json JsonConverter for the StrongTypedId library</Description>
<Copyright>Steffen Skov 2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/steffenskov/StrongTypedId</PackageProjectUrl>
<PackageTags>strongly-typed, Id, newtonsoft</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
8 changes: 0 additions & 8 deletions src/StrongTypedId.Swagger/StrongTypedId.Swagger.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Description>Swagger support for the StrongTypedId library</Description>
<Copyright>Steffen Skov 2023</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/steffenskov/StrongTypedId</PackageProjectUrl>
<PackageTags>strongly-typed, Id, swagger</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
13 changes: 8 additions & 5 deletions src/StrongTypedId/StrongTypedEnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ protected StrongTypedEnumValue(TEnum value) : base(value.ToString())
}
}

protected StrongTypedEnumValue(string value) : base(value)
protected StrongTypedEnumValue(string value) : this(Parse(value))
{
if (!Enum.TryParse<TEnum>(value, out _))
{
throw new ArgumentException($@"Value ""{value}"" is not defined in enum {typeof(TEnum).Name}", nameof(value));
}
}

public TEnum PrimitiveEnumValue => Enum.Parse<TEnum>(PrimitiveValue, true);

private static TEnum Parse(string value)
{
return Enum.TryParse<TEnum>(value, out var result)
? result
: throw new ArgumentException($@"Value ""{value}"" is not defined in enum {typeof(TEnum).Name}", nameof(value));
}

public static IEnumerable<TSelf> GetValidValues()
{
return Enum.GetValues<TEnum>().Select(value => Create(value.ToString()));
Expand Down
8 changes: 0 additions & 8 deletions src/StrongTypedId/StrongTypedId.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Steffen Skov</Authors>
<Company>Steffen Skov</Company>
<Description>A super small library for providing strong typed Ids (as opposed to using primitives)</Description>
<Copyright>Steffen Skov 2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/steffenskov/StrongTypedId</PackageProjectUrl>
<PackageTags>strongly-typed, Id</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class ContainerFixture : IAsyncLifetime
public ContainerFixture()
{
StrongTypedMongo.AddStrongTypedMongoSerializers(typeof(FakeId).Assembly);
_mongoContainer = new MongoDbBuilder()
.WithImage("mongo:latest")
_mongoContainer = new MongoDbBuilder("mongo:latest")
.WithUsername("mongo")
.WithPassword("secret")
.WithPortBinding(27017, 27017)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);NU1504;NU1008</NoWarn>
Expand All @@ -25,7 +21,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="LiteDB"/>

</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions tests/StrongTypedId.UnitTests/StrongTypedEnumValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ public void Ctor_ValidString_Created()
// Assert
Assert.Equal(FakeEnum.Value1, strongEnum.PrimitiveEnumValue);
}

[Fact]
public void Ctor_NumericString_PrimitiveBecomesEnumName()
{
// Arrange
var primitive = ((int)FakeEnum.Value1).ToString();

// Act
var strongEnum = new FakeStrongEnumValue(primitive);

// Assert
Assert.Equal(nameof(FakeEnum.Value1), strongEnum.PrimitiveValue);
}
}

file class FakeStrongEnumValue : StrongTypedEnumValue<FakeStrongEnumValue, FakeEnum>
Expand Down
4 changes: 0 additions & 4 deletions tests/StrongTypedId.UnitTests/StrongTypedId.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);NU1504;NU1008</NoWarn>
Expand Down