Skip to content

Commit 340b598

Browse files
authored
Automatically add typedid (#161)
* Automatically add any typedid files without needing to be explicit * Add tests
1 parent 844501b commit 340b598

File tree

11 files changed

+78
-0
lines changed

11 files changed

+78
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<ItemGroup>
3+
<None Remove="$(MSBuildProjectDirectory)\**\*.typedid" />
4+
<AdditionalFiles Include="$(MSBuildProjectDirectory)\**\*.typedid" Visible="False" />
5+
</ItemGroup>
6+
</Project>

src/StronglyTypedIds/StronglyTypedIds.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31+
<None Include="StronglyTypedId.props" Pack="true" PackagePath="build" />
3132
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
3233
<None Include="$(OutputPath)\StronglyTypedIds.Attributes.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
3334
<None Include="$(OutputPath)\StronglyTypedIds.Attributes.dll" Pack="true" PackagePath="lib\netstandard2.0" Visible="true" />

test/StronglyTypedIds.IntegrationTests.Types/Enums.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public partial struct ConvertersStringId2 { }
5858
[StronglyTypedId("nullablestring-full")]
5959
public partial struct NullableStringId { }
6060

61+
[StronglyTypedId("simple")]
62+
public partial struct SimpleCustomId { }
63+
6164
public partial class SomeType<T> where T : new()
6265
{
6366
public partial record struct NestedType<TKey, TValue>

test/StronglyTypedIds.IntegrationTests.Types/StronglyTypedIds.IntegrationTests.Types.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3+
<Import Project="..\..\src\StronglyTypedIds\StronglyTypedId.props" />
4+
35
<PropertyGroup>
46
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
57
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net48;$(TargetFrameworks)</TargetFrameworks>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
partial struct PLACEHOLDERID
2+
{
3+
public int Value { get; }
4+
5+
public PLACEHOLDERID(int value)
6+
{
7+
Value = value;
8+
}
9+
}

test/StronglyTypedIds.IntegrationTests/Enums.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ internal partial struct ConvertersStringId2 { }
5858
[StronglyTypedId("nullablestring-full")]
5959
internal partial struct NullableStringId { }
6060

61+
[StronglyTypedId("simple")]
62+
internal partial struct SimpleCustomId { }
63+
6164
internal partial class SomeType<T> where T : new()
6265
{
6366
internal partial record struct NestedType<TKey, TValue>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using StronglyTypedIds.IntegrationTests.Types;
2+
using Xunit;
3+
4+
namespace StronglyTypedIds.IntegrationTests;
5+
6+
public class SimpleCustomIdTests
7+
{
8+
[Fact]
9+
public void SameValuesAreEqual()
10+
{
11+
var id = 123;
12+
var foo1 = new SimpleCustomId(id);
13+
var foo2 = new SimpleCustomId(id);
14+
15+
Assert.Equal(foo1, foo2);
16+
}
17+
18+
[Fact]
19+
public void DifferentValuesAreUnequal()
20+
{
21+
var foo1 = new SimpleCustomId(1);
22+
var foo2 = new SimpleCustomId(2);
23+
24+
Assert.NotEqual(foo1, foo2);
25+
}
26+
}

test/StronglyTypedIds.IntegrationTests/StronglyTypedIds.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="..\..\src\StronglyTypedIds\StronglyTypedId.props" />
23

34
<PropertyGroup>
45
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
partial struct PLACEHOLDERID
2+
{
3+
public int Value { get; }
4+
5+
public PLACEHOLDERID(int value)
6+
{
7+
Value = value;
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
partial struct PLACEHOLDERID
2+
{
3+
public int Value { get; }
4+
5+
public PLACEHOLDERID(int value)
6+
{
7+
Value = value;
8+
}
9+
}

0 commit comments

Comments
 (0)