Skip to content

Commit d91276e

Browse files
committed
Rename package to StrucTId, TValue > TId
This plays with the `<TId>` icon.
1 parent e342c32 commit d91276e

16 files changed

+41
-43
lines changed

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Icon](img/icon-32.png) StructId
1+
![Icon](assets/img/icon-32.png) StrucTId
22
============
33

44
[![Version](https://img.shields.io/nuget/vpre/StructId.svg?color=royalblue)](https://www.nuget.org/packages/StructId)
@@ -24,15 +24,15 @@ Unlike other such libraries for .NET, StructId introduces several unique feature
2424
1. Leverages newest language and runtime features for cleaner and more efficient code,
2525
such as:
2626
1. IParsable<T> for parsing from strings.
27-
1. Static interface members, for consistent `TSelf.New(TValue value)` factory
28-
method and proper type constraint (via a provided `INewable<TSelf, TValue>` interface).
27+
1. Static interface members, for consistent `TSelf.New(TId value)` factory
28+
method and proper type constraint (via a provided `INewable<TSelf, TId>` interface).
2929

3030

3131
## Usage
3232

3333
After installing the [StructId package](https://nuget.org/packages/StructId), the project
3434
(with a direct reference to the `StructId` package) will contain the main interfaces
35-
`IStruct` (for string-typed IDs) and `IStructId<TValue>`.
35+
`IStruct` (for string-typed IDs) and `IStructId<TId>`.
3636

3737
> NOTE: the package only needs to be installed in the top-level project in your solution,
3838
> since analyzers/generators will [automatically propagate to referencing projects]((https://github.com/dotnet/sdk/issues/1212)).
@@ -44,7 +44,7 @@ you publish one).
4444
The default target namespace for the included types will match the `RootNamespace` of the
4545
project, but can be customized by setting the `StructIdNamespace` property.
4646

47-
You can simply declare a new ID type by implementing `IStructId<TValue>`:
47+
You can simply declare a new ID type by implementing `IStructId<TId>`:
4848

4949
```csharp
5050
public readonly partial record struct UserId : IStructId<Guid>;

src/StructId.Analyzer/EntityFrameworkGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void GenerateValueSelector(SourceProductionContext context, ImmutableArray<Templ
3030
context.AddSource($"ValueConverterSelector.cs", output);
3131
}
3232

33-
record StructIdModel(string TSelf, string TValueType)
33+
record StructIdModel(string TSelf, string TIdType)
3434
{
35-
public string TValue => TValueType switch
35+
public string TId => TIdType switch
3636
{
3737
"System.String" => "string",
3838
"System.Int32" => "int",
@@ -53,7 +53,7 @@ record StructIdModel(string TSelf, string TValueType)
5353
"System.UInt16" => "ushort",
5454
"System.Int16" => "short",
5555
"System.Object" => "object",
56-
_ => TValueType
56+
_ => TIdType
5757
};
5858
}
5959

src/StructId.Analyzer/EntityFrameworkSelector.sbn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static class StructIdDbContextOptionsBuilderExtensions
3939
{{~ for id in Ids ~}}
4040
if (modelClrType == typeof({{ id.TSelf }}))
4141
yield return converters.GetOrAdd((modelClrType, providerClrType), key => new ValueConverterInfo(
42-
key.ModelClrType, key.ProviderClrType ?? typeof({{ id.TValue }}),
42+
key.ModelClrType, key.ProviderClrType ?? typeof({{ id.TId }}),
4343
info => new {{ id.TSelf }}.EntityFrameworkValueConverter(info.MappingHints)));
4444

4545
{{~ end ~}}

src/StructId.Analyzer/TemplateGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void GenerateCode(SourceProductionContext context, TemplateArgs args)
8383
// Simple names suffices since we emit a partial in the same namespace
8484
.Replace("TSelf", args.StructId.Name)
8585
.Replace("Self", args.StructId.Name)
86-
.Replace("TValue", args.ValueType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
86+
.Replace("TId", args.ValueType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
8787

8888
// parse template into a C# compilation unit
8989
var parseable = CSharpSyntaxTree.ParseText(template).GetCompilationUnitRoot();

src/StructId.Package/StructId.Package.msbuildproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.Build.NoTargets/3.7.0">
22
<PropertyGroup>
33
<TargetFramework>netstandard2.0</TargetFramework>
4-
<PackageId>StructId</PackageId>
4+
<PackageId>StrucTId</PackageId>
55
<DevelopmentDependency>true</DevelopmentDependency>
66
<Description>Stronly typed ids using readonly record structs.s</Description>
77
<PackageTags>dotnet record struct typed id</PackageTags>

src/StructId.Tests/TestExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ public static string Replace(this string template, Regex regex, string value)
7272
[GeneratedRegex(@"\bTSelf\b")]
7373
private static partial Regex TSelfExpr();
7474

75-
[GeneratedRegex(@"\bTValue\b")]
75+
[GeneratedRegex(@"\bTId\b")]
7676
private static partial Regex TValueExpr();
7777
}

src/StructId/INewableT.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace StructId;
66
/// Interface implemented by <see cref="IStructId{T}"/>
77
/// that support creating new instances of the identifier.
88
/// </summary>
9-
public interface INewable<TSelf, TValue>
9+
public interface INewable<TSelf, TId>
1010
{
1111
/// <summary>
1212
/// Creates a new identifier from the given identifier value.
1313
/// </summary>
14-
public abstract static TSelf New(TValue value);
14+
public abstract static TSelf New(TId value);
1515
}

src/StructId/IStructIdT.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace StructId;
55
/// <summary>
66
/// Interface for struct-based identifiers.
77
/// </summary>
8-
/// <typeparam name="T">The struct type for the inner <see cref="Value"/> of the identifier.</typeparam>
9-
public partial interface IStructId<T> where T : struct
8+
/// <typeparam name="TId">The struct type for the inner <see cref="Value"/> of the identifier.</typeparam>
9+
public partial interface IStructId<TId> where TId : struct
1010
{
1111
/// <summary>
1212
/// Gets the underlying value of the identifier.
1313
/// </summary>
14-
T Value { get; }
14+
TId Value { get; }
1515
}

src/StructId/StructIdConverters.JsonConverter.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ namespace StructId;
99

1010
public static partial class StructIdConverters
1111
{
12-
#if NET7_0_OR_GREATER
13-
public class SystemTextJsonConverter<TSelf, TValue> : JsonConverter<TSelf>
14-
where TSelf : IStructId<TValue>, INewable<TSelf, TValue>
15-
where TValue: struct, IParsable<TValue>
12+
public class SystemTextJsonConverter<TSelf, TId> : JsonConverter<TSelf>
13+
where TSelf : IStructId<TId>, INewable<TSelf, TId>
14+
where TId: struct, IParsable<TId>
1615
{
1716
public override TSelf Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
18-
=> TSelf.New(TValue.Parse(reader.GetString() ?? throw new FormatException("Unsupported null value for struct id."), CultureInfo.InvariantCulture));
17+
=> TSelf.New(TId.Parse(reader.GetString() ?? throw new FormatException("Unsupported null value for struct id."), CultureInfo.InvariantCulture));
1918

2019
public override void Write(Utf8JsonWriter writer, TSelf value, JsonSerializerOptions options)
2120
{
@@ -24,7 +23,7 @@ public override void Write(Utf8JsonWriter writer, TSelf value, JsonSerializerOpt
2423
case Guid guid:
2524
writer.WriteStringValue(guid);
2625
break;
27-
case TValue inner:
26+
case TId inner:
2827
writer.WriteRawValue(inner.ToString());
2928
break;
3029
default:
@@ -33,7 +32,7 @@ public override void Write(Utf8JsonWriter writer, TSelf value, JsonSerializerOpt
3332
}
3433

3534
public override TSelf ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options)
36-
=> TSelf.New(TValue.Parse(reader.GetString() ?? throw new FormatException("Unsupported null value for struct id."), CultureInfo.InvariantCulture));
35+
=> TSelf.New(TId.Parse(reader.GetString() ?? throw new FormatException("Unsupported null value for struct id."), CultureInfo.InvariantCulture));
3736

3837
public override void WriteAsPropertyName(global::System.Text.Json.Utf8JsonWriter writer, TSelf value, global::System.Text.Json.JsonSerializerOptions options)
3938
=> writer.WritePropertyName(value.Value.ToString());
@@ -54,5 +53,4 @@ public override TSelf ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonRe
5453
public override void WriteAsPropertyName(global::System.Text.Json.Utf8JsonWriter writer, TSelf value, global::System.Text.Json.JsonSerializerOptions options)
5554
=> writer.WritePropertyName(value.Value);
5655
}
57-
#endif
5856
}

src/StructId/Templates/EntityFramework.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
55
using StructId;
66

7-
readonly partial record struct TSelf : INewable<TSelf, TValue>
7+
readonly partial record struct TSelf : INewable<TSelf, TId>
88
{
99
/// <summary>
1010
/// Provides value conversion for Entity Framework Core
1111
/// </summary>
12-
public partial class EntityFrameworkValueConverter : ValueConverter<TSelf, TValue>
12+
public partial class EntityFrameworkValueConverter : ValueConverter<TSelf, TId>
1313
{
1414
public EntityFrameworkValueConverter() : this(null) { }
1515

0 commit comments

Comments
 (0)