Skip to content

Commit 772ec6b

Browse files
committed
Added support for internal identifiers.
1 parent fd8389d commit 772ec6b

12 files changed

+39
-35
lines changed

Diff for: src/LightResults.Extensions.GeneratedIdentifier/GeneratedIdentifierSourceGenerator.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private static bool Filter(SyntaxNode syntaxNode, CancellationToken cancellation
7272
var containingDeclarations = namedTypeSymbol.GetContainingDeclarations(cancellationToken);
7373
var symbolName = namedTypeSymbol.Name;
7474
var isStruct = namedTypeSymbol.TypeKind == TypeKind.Struct;
75+
var isPublic = namedTypeSymbol.DeclaredAccessibility == Accessibility.Public;
7576

7677
var attribute = context.Attributes[0].AttributeClass!;
7778
if (attribute.TypeArguments.Length != 1)
@@ -107,7 +108,7 @@ private static bool Filter(SyntaxNode syntaxNode, CancellationToken cancellation
107108
break;
108109
}
109110

110-
var symbol = new Identifier(containingDeclarations, symbolName, isStruct, declaredValueType, fullValueType);
111+
var symbol = new Identifier(containingDeclarations, symbolName, isStruct, isPublic, declaredValueType, fullValueType);
111112

112113
return symbol;
113114
}
@@ -119,6 +120,7 @@ private static void GenerateIdentifier(SourceProductionContext context, Immutabl
119120
var symbolNamespace = symbol.ContainingDeclarations.ToNamespace();
120121
var symbolName = symbol.Name;
121122
var isStruct = symbol.IsStruct;
123+
var isPublic = symbol.IsPublic;
122124
var declaredValueType = symbol.DeclaredValueType;
123125
var fullValueType = symbol.FullValueType;
124126

@@ -157,7 +159,7 @@ namespace {symbolNamespace};
157159
source.AppendLine($$"""
158160
[TypeConverter(typeof({{symbolName}}TypeConverter))]
159161
[JsonConverter(typeof({{symbolName}}JsonConverter))]
160-
{{(isStruct ? "readonly" : "sealed")}} partial {{(isStruct ? "struct" : "class")}} {{symbolName}} :
162+
{{(isPublic ? "public" : "internal")}} {{(isStruct ? "readonly" : "sealed")}} partial {{(isStruct ? "struct" : "class")}} {{symbolName}} :
161163
ICreatableValueObject<{{declaredValueType}}, {{symbolName}}>,
162164
"""
163165
);
@@ -664,7 +666,7 @@ private static Result Validate({{declaredValueType}} value)
664666
);
665667

666668
source.AppendLine($$"""
667-
public class {{symbolName}}TypeConverter : TypeConverter
669+
{{(isPublic ? "public" : "internal")}} sealed class {{symbolName}}TypeConverter : TypeConverter
668670
{
669671
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
670672
{
@@ -683,7 +685,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext? context, Type source
683685
"""
684686
);
685687
source.AppendLine($$"""
686-
public class {{symbolName}}JsonConverter : JsonConverter<{{symbolName}}>
688+
{{(isPublic ? "public" : "internal")}} sealed class {{symbolName}}JsonConverter : JsonConverter<{{symbolName}}>
687689
{
688690
public override void Write(Utf8JsonWriter writer, {{symbolName}} identifier, JsonSerializerOptions options)
689691
{
@@ -730,13 +732,15 @@ private readonly record struct Identifier(
730732
EquatableImmutableArray<Declaration> ContainingDeclarations,
731733
string Name,
732734
bool IsStruct,
735+
bool IsPublic,
733736
string DeclaredValueType,
734737
string FullValueType
735738
)
736739
{
737740
public EquatableImmutableArray<Declaration> ContainingDeclarations { get; } = ContainingDeclarations;
738741
public string Name { get; } = Name;
739742
public bool IsStruct { get; } = IsStruct;
743+
public bool IsPublic { get; } = IsPublic;
740744
public string DeclaredValueType { get; } = DeclaredValueType;
741745
public string FullValueType { get; } = FullValueType;
742746
}

Diff for: src/LightResults.Extensions.GeneratedIdentifier/LightResults.Extensions.GeneratedIdentifier.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<!-- Output -->
3737
<PropertyGroup>
3838
<AssemblyName>LightResults.Extensions.GeneratedIdentifier</AssemblyName>
39-
<Version>9.0.0-preview.8</Version>
39+
<Version>9.0.0-preview.9</Version>
4040
<AssemblyVersion>9.0.0.0</AssemblyVersion>
4141
<FileVersion>9.0.0.0</FileVersion>
4242
<NeutralLanguage>en-US</NeutralLanguage>

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateGuidIdentifier_WithNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace MyProject.Identifiers;
2121

2222
[TypeConverter(typeof(TestGuidIdTypeConverter))]
2323
[JsonConverter(typeof(TestGuidIdJsonConverter))]
24-
readonly partial struct TestGuidId :
24+
public readonly partial struct TestGuidId :
2525
ICreatableValueObject<Guid, TestGuidId>,
2626
IParsableValueObject<TestGuidId>,
2727
IValueObject<Guid, TestGuidId>,
@@ -199,7 +199,7 @@ readonly partial struct TestGuidId :
199199
}
200200
}
201201

202-
public class TestGuidIdTypeConverter : TypeConverter
202+
public sealed class TestGuidIdTypeConverter : TypeConverter
203203
{
204204
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
205205
{
@@ -215,7 +215,7 @@ public class TestGuidIdTypeConverter : TypeConverter
215215
}
216216
}
217217

218-
public class TestGuidIdJsonConverter : JsonConverter<TestGuidId>
218+
public sealed class TestGuidIdJsonConverter : JsonConverter<TestGuidId>
219219
{
220220
public override void Write(Utf8JsonWriter writer, TestGuidId identifier, JsonSerializerOptions options)
221221
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateGuidIdentifier_WithoutNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using LightResults.Extensions.ValueObjects;
1919

2020
[TypeConverter(typeof(TestGuidIdTypeConverter))]
2121
[JsonConverter(typeof(TestGuidIdJsonConverter))]
22-
readonly partial struct TestGuidId :
22+
public readonly partial struct TestGuidId :
2323
ICreatableValueObject<Guid, TestGuidId>,
2424
IParsableValueObject<TestGuidId>,
2525
IValueObject<Guid, TestGuidId>,
@@ -197,7 +197,7 @@ readonly partial struct TestGuidId :
197197
}
198198
}
199199

200-
public class TestGuidIdTypeConverter : TypeConverter
200+
public sealed class TestGuidIdTypeConverter : TypeConverter
201201
{
202202
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
203203
{
@@ -213,7 +213,7 @@ public class TestGuidIdTypeConverter : TypeConverter
213213
}
214214
}
215215

216-
public class TestGuidIdJsonConverter : JsonConverter<TestGuidId>
216+
public sealed class TestGuidIdJsonConverter : JsonConverter<TestGuidId>
217217
{
218218
public override void Write(Utf8JsonWriter writer, TestGuidId identifier, JsonSerializerOptions options)
219219
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateIntIdentifier_WithNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace MyProject.Identifiers;
2121

2222
[TypeConverter(typeof(TestIntIdTypeConverter))]
2323
[JsonConverter(typeof(TestIntIdJsonConverter))]
24-
readonly partial struct TestIntId :
24+
public readonly partial struct TestIntId :
2525
ICreatableValueObject<int, TestIntId>,
2626
IParsableValueObject<TestIntId>,
2727
IValueObject<int, TestIntId>,
@@ -202,7 +202,7 @@ readonly partial struct TestIntId :
202202
}
203203
}
204204

205-
public class TestIntIdTypeConverter : TypeConverter
205+
public sealed class TestIntIdTypeConverter : TypeConverter
206206
{
207207
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
208208
{
@@ -218,7 +218,7 @@ public class TestIntIdTypeConverter : TypeConverter
218218
}
219219
}
220220

221-
public class TestIntIdJsonConverter : JsonConverter<TestIntId>
221+
public sealed class TestIntIdJsonConverter : JsonConverter<TestIntId>
222222
{
223223
public override void Write(Utf8JsonWriter writer, TestIntId identifier, JsonSerializerOptions options)
224224
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateIntIdentifier_WithoutNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using LightResults.Extensions.ValueObjects;
1919

2020
[TypeConverter(typeof(TestIntIdTypeConverter))]
2121
[JsonConverter(typeof(TestIntIdJsonConverter))]
22-
readonly partial struct TestIntId :
22+
public readonly partial struct TestIntId :
2323
ICreatableValueObject<int, TestIntId>,
2424
IParsableValueObject<TestIntId>,
2525
IValueObject<int, TestIntId>,
@@ -200,7 +200,7 @@ readonly partial struct TestIntId :
200200
}
201201
}
202202

203-
public class TestIntIdTypeConverter : TypeConverter
203+
public sealed class TestIntIdTypeConverter : TypeConverter
204204
{
205205
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
206206
{
@@ -216,7 +216,7 @@ public class TestIntIdTypeConverter : TypeConverter
216216
}
217217
}
218218

219-
public class TestIntIdJsonConverter : JsonConverter<TestIntId>
219+
public sealed class TestIntIdJsonConverter : JsonConverter<TestIntId>
220220
{
221221
public override void Write(Utf8JsonWriter writer, TestIntId identifier, JsonSerializerOptions options)
222222
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateLongIdentifier_WithNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace MyProject.Identifiers;
2121

2222
[TypeConverter(typeof(TestLongIdTypeConverter))]
2323
[JsonConverter(typeof(TestLongIdJsonConverter))]
24-
readonly partial struct TestLongId :
24+
public readonly partial struct TestLongId :
2525
ICreatableValueObject<long, TestLongId>,
2626
IParsableValueObject<TestLongId>,
2727
IValueObject<long, TestLongId>,
@@ -202,7 +202,7 @@ readonly partial struct TestLongId :
202202
}
203203
}
204204

205-
public class TestLongIdTypeConverter : TypeConverter
205+
public sealed class TestLongIdTypeConverter : TypeConverter
206206
{
207207
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
208208
{
@@ -218,7 +218,7 @@ public class TestLongIdTypeConverter : TypeConverter
218218
}
219219
}
220220

221-
public class TestLongIdJsonConverter : JsonConverter<TestLongId>
221+
public sealed class TestLongIdJsonConverter : JsonConverter<TestLongId>
222222
{
223223
public override void Write(Utf8JsonWriter writer, TestLongId identifier, JsonSerializerOptions options)
224224
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateLongIdentifier_WithoutNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using LightResults.Extensions.ValueObjects;
1919

2020
[TypeConverter(typeof(TestLongIdTypeConverter))]
2121
[JsonConverter(typeof(TestLongIdJsonConverter))]
22-
readonly partial struct TestLongId :
22+
public readonly partial struct TestLongId :
2323
ICreatableValueObject<long, TestLongId>,
2424
IParsableValueObject<TestLongId>,
2525
IValueObject<long, TestLongId>,
@@ -200,7 +200,7 @@ readonly partial struct TestLongId :
200200
}
201201
}
202202

203-
public class TestLongIdTypeConverter : TypeConverter
203+
public sealed class TestLongIdTypeConverter : TypeConverter
204204
{
205205
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
206206
{
@@ -216,7 +216,7 @@ public class TestLongIdTypeConverter : TypeConverter
216216
}
217217
}
218218

219-
public class TestLongIdJsonConverter : JsonConverter<TestLongId>
219+
public sealed class TestLongIdJsonConverter : JsonConverter<TestLongId>
220220
{
221221
public override void Write(Utf8JsonWriter writer, TestLongId identifier, JsonSerializerOptions options)
222222
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateShortIdentifier_WithNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace MyProject.Identifiers;
2121

2222
[TypeConverter(typeof(TestShortIdTypeConverter))]
2323
[JsonConverter(typeof(TestShortIdJsonConverter))]
24-
readonly partial struct TestShortId :
24+
public readonly partial struct TestShortId :
2525
ICreatableValueObject<short, TestShortId>,
2626
IParsableValueObject<TestShortId>,
2727
IValueObject<short, TestShortId>,
@@ -202,7 +202,7 @@ readonly partial struct TestShortId :
202202
}
203203
}
204204

205-
public class TestShortIdTypeConverter : TypeConverter
205+
public sealed class TestShortIdTypeConverter : TypeConverter
206206
{
207207
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
208208
{
@@ -218,7 +218,7 @@ public class TestShortIdTypeConverter : TypeConverter
218218
}
219219
}
220220

221-
public class TestShortIdJsonConverter : JsonConverter<TestShortId>
221+
public sealed class TestShortIdJsonConverter : JsonConverter<TestShortId>
222222
{
223223
public override void Write(Utf8JsonWriter writer, TestShortId identifier, JsonSerializerOptions options)
224224
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateShortIdentifier_WithoutNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using LightResults.Extensions.ValueObjects;
1919

2020
[TypeConverter(typeof(TestShortIdTypeConverter))]
2121
[JsonConverter(typeof(TestShortIdJsonConverter))]
22-
readonly partial struct TestShortId :
22+
public readonly partial struct TestShortId :
2323
ICreatableValueObject<short, TestShortId>,
2424
IParsableValueObject<TestShortId>,
2525
IValueObject<short, TestShortId>,
@@ -200,7 +200,7 @@ readonly partial struct TestShortId :
200200
}
201201
}
202202

203-
public class TestShortIdTypeConverter : TypeConverter
203+
public sealed class TestShortIdTypeConverter : TypeConverter
204204
{
205205
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
206206
{
@@ -216,7 +216,7 @@ public class TestShortIdTypeConverter : TypeConverter
216216
}
217217
}
218218

219-
public class TestShortIdJsonConverter : JsonConverter<TestShortId>
219+
public sealed class TestShortIdJsonConverter : JsonConverter<TestShortId>
220220
{
221221
public override void Write(Utf8JsonWriter writer, TestShortId identifier, JsonSerializerOptions options)
222222
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateStringIdentifier_WithNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace MyProject.Identifiers;
2121

2222
[TypeConverter(typeof(TestStringIdTypeConverter))]
2323
[JsonConverter(typeof(TestStringIdJsonConverter))]
24-
sealed partial class TestStringId :
24+
public sealed partial class TestStringId :
2525
ICreatableValueObject<string, TestStringId>,
2626
IValueObject<string, TestStringId>,
2727
IComparable<TestStringId>,
@@ -182,7 +182,7 @@ sealed partial class TestStringId :
182182
}
183183
}
184184

185-
public class TestStringIdTypeConverter : TypeConverter
185+
public sealed class TestStringIdTypeConverter : TypeConverter
186186
{
187187
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
188188
{
@@ -198,7 +198,7 @@ public class TestStringIdTypeConverter : TypeConverter
198198
}
199199
}
200200

201-
public class TestStringIdJsonConverter : JsonConverter<TestStringId>
201+
public sealed class TestStringIdJsonConverter : JsonConverter<TestStringId>
202202
{
203203
public override void Write(Utf8JsonWriter writer, TestStringId identifier, JsonSerializerOptions options)
204204
{

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateStringIdentifier_WithoutNamespace.verified.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using LightResults.Extensions.ValueObjects;
1919

2020
[TypeConverter(typeof(TestStringIdTypeConverter))]
2121
[JsonConverter(typeof(TestStringIdJsonConverter))]
22-
sealed partial class TestStringId :
22+
public sealed partial class TestStringId :
2323
ICreatableValueObject<string, TestStringId>,
2424
IValueObject<string, TestStringId>,
2525
IComparable<TestStringId>,
@@ -180,7 +180,7 @@ sealed partial class TestStringId :
180180
}
181181
}
182182

183-
public class TestStringIdTypeConverter : TypeConverter
183+
public sealed class TestStringIdTypeConverter : TypeConverter
184184
{
185185
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
186186
{
@@ -196,7 +196,7 @@ public class TestStringIdTypeConverter : TypeConverter
196196
}
197197
}
198198

199-
public class TestStringIdJsonConverter : JsonConverter<TestStringId>
199+
public sealed class TestStringIdJsonConverter : JsonConverter<TestStringId>
200200
{
201201
public override void Write(Utf8JsonWriter writer, TestStringId identifier, JsonSerializerOptions options)
202202
{

0 commit comments

Comments
 (0)