Skip to content

Commit 674d42c

Browse files
committed
Add docs to generated public types and members.
1 parent 98b833a commit 674d42c

81 files changed

Lines changed: 2356 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Copyright>(c) $([System.DateTime]::Now.Year), Pawel Gerr. All rights reserved.</Copyright>
5-
<VersionPrefix>9.5.2</VersionPrefix>
5+
<VersionPrefix>9.5.3</VersionPrefix>
66
<Authors>Pawel Gerr</Authors>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageProjectUrl>https://github.com/PawelGerr/Thinktecture.Runtime.Extensions</PackageProjectUrl>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ See [wiki](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki) fo
3030
* [Value Objects: Solving Primitive Obsession in .NET](https://www.thinktecture.com/en/net/value-objects-solving-primitive-obsession-in-net/)
3131
* [Handling Complexity: Introducing Complex Value Objects in .NET](https://www.thinktecture.com/en/net/handling-complexity-introducing-complex-value-objects-in-dotnet/)
3232
* [Value Objects in .NET: Integration with Frameworks and Libraries](https://www.thinktecture.com/en/net/value-objects-integration-with-frameworks-and-libraries/)
33+
* [Value Objects in .NET: Enhancing Business Semantics](https://www.thinktecture.com/en/net/value-objects-in-dotnet-enhancing-business-semantics/)
3334

3435
**Smart Enums articles**:
3536
* [Smart Enums: Beyond Traditional Enumerations in .NET](https://www.thinktecture.com/en/net/smart-enums-beyond-traditional-enumerations-in-dotnet/)
37+
* [Smart Enums: Adding Domain Logic to Enumerations in .NET](https://www.thinktecture.com/net/smart-enums-adding-domain-logic-to-enumerations-in-dotnet/)
3638

3739
**Discriminated Unions articles**:
3840
* [Discriminated Unions: Representation of Alternative Types in .NET](https://www.thinktecture.com/net/discriminated-unions-representation-of-alternative-types-in-dotnet/)

docs

Submodule docs updated from 0258a71 to 628c042

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/DiagnosticsDescriptors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal static class DiagnosticsDescriptors
3333
public static readonly DiagnosticDescriptor TypeMustNotBeInsideGenericType = new("TTRESG052", "The type must not be inside generic type", "Type '{0}' must not be inside a generic type", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);
3434
public static readonly DiagnosticDescriptor UnionDerivedTypesMustNotBeGeneric = new("TTRESG053", "Derived type of a union must not be generic", "Derived type '{0}' of a union must not be generic", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);
3535
public static readonly DiagnosticDescriptor UnionMustBeSealedOrHavePrivateConstructorsOnly = new("TTRESG054", "Discriminated union must be sealed or have private constructors only", "Discriminated union '{0}' must be sealed or have private constructors only", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);
36-
public static readonly DiagnosticDescriptor UnionRecordMustBeSealed = new("TTRESG055", "Discriminated union implemented using a record must be sealed", "Discriminated union '{0}' using a record must be sealed", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);
36+
public static readonly DiagnosticDescriptor UnionRecordMustBeSealed = new("TTRESG055", "Discriminated union implemented using a record must be sealed", "Discriminated union '{0}' using a record must be sealed. Use a class for nesting unions.", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);
3737
public static readonly DiagnosticDescriptor NonAbstractDerivedUnionIsLessAccessibleThanBaseUnion = new("TTRESG056", "Non-abstract derived union is less accessible than base union", "Non-abstract derived union '{0}' is less accessible than base union '{1}'", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);
3838
public static readonly DiagnosticDescriptor AllowDefaultStructsCannotBeTrueIfValueObjectIsStructButKeyTypeIsClass = new("TTRESG057", "'AllowDefaultStructs' must be 'false' if Value Object is a struct but key type is a reference type", "'AllowDefaultStructs' of type '{0}' must be 'false' because it is a struct but the key type '{1}' is a reference type", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);
3939
public static readonly DiagnosticDescriptor AllowDefaultStructsCannotBeTrueIfSomeMembersDisallowDefaultValues = new("TTRESG058", "'AllowDefaultStructs' must be 'false' if some members disallow default values", "'AllowDefaultStructs' of type '{0}' must be 'false' because following members disallow default values: {1}", nameof(ThinktectureRuntimeExtensionsAnalyzer), DiagnosticSeverity.Error, true);

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ComplexValueObjectCodeGenerator.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ private void GenerateCreateMethod()
119119

120120
_sb.Append(@"
121121
122+
/// <summary>
123+
/// Creates an instance of the ").AppendTypeForXmlComment(_state).Append(@" type if the provided values pass validation.
124+
/// </summary>");
125+
126+
for (var i = 0; i < fieldsAndProperties.Count; i++)
127+
{
128+
var memberInfo = fieldsAndProperties[i];
129+
130+
_sb.Append(@"
131+
/// <param name=""").Append(memberInfo.ArgumentName).Append(@""">The value to be used for object creation.</param>");
132+
}
133+
134+
_sb.Append(@"
135+
/// <returns>A newly created ").AppendTypeForXmlComment(_state).Append(@" instance.</returns>
136+
/// <exception cref=""System.ComponentModel.DataAnnotations.ValidationException"">Thrown when the provided values fail validation.</exception>
122137
public static ").AppendTypeFullyQualified(_state).Append(" ").Append(_state.Settings.CreateFactoryMethodName).Append("(").RenderArgumentsWithType(fieldsAndProperties, prefix: @"
123138
", comma: ",").Append(@")
124139
{
@@ -146,6 +161,27 @@ private void GenerateTryCreateMethod()
146161

147162
_sb.Append(@"
148163
164+
/// <summary>
165+
/// Attempts to create an instance of type ").AppendTypeForXmlComment(_state).Append(@"
166+
/// if the provided values pass validation.
167+
/// </summary>");
168+
169+
for (var i = 0; i < fieldsAndProperties.Count; i++)
170+
{
171+
var memberInfo = fieldsAndProperties[i];
172+
173+
_sb.Append(@"
174+
/// <param name=""").Append(memberInfo.ArgumentName).Append(@""">The value to be used for object creation.</param>");
175+
}
176+
177+
_sb.Append(@"
178+
/// <param name=""obj"">
179+
/// When this method returns, contains the created instance of type ").AppendTypeForXmlComment(_state).Append(@"
180+
/// if the operation is successful; otherwise, <c>null</c>.
181+
/// </param>
182+
/// <returns>
183+
/// <c>true</c> if the instance is successfully created; otherwise, <c>false</c>.
184+
/// </returns>
149185
public static bool ").Append(_state.Settings.TryCreateFactoryMethodName).Append("(");
150186

151187
_sb.RenderArgumentsWithType(fieldsAndProperties, @"
@@ -169,6 +205,31 @@ private void GenerateTryCreateMethod()
169205

170206
_sb.Append(@"
171207
208+
/// <summary>
209+
/// Attempts to create an instance of type ").AppendTypeForXmlComment(_state).Append(@"
210+
/// if the provided values pass validation.
211+
/// </summary>");
212+
213+
for (var i = 0; i < fieldsAndProperties.Count; i++)
214+
{
215+
var memberInfo = fieldsAndProperties[i];
216+
217+
_sb.Append(@"
218+
/// <param name=""").Append(memberInfo.ArgumentName).Append(@""">The value to be used for object creation.</param>");
219+
}
220+
221+
_sb.Append(@"
222+
/// <param name=""obj"">
223+
/// When this method returns, contains the created instance of type ").AppendTypeForXmlComment(_state).Append(@"
224+
/// if the operation is successful; otherwise, <c>null</c>.
225+
/// </param>
226+
/// <param name=""validationError"">
227+
/// When this method returns, contains the ").AppendTypeForXmlComment(_state.ValidationError).Append(@"
228+
/// describing why validation failed, if the operation fails; otherwise, <c>null</c>.
229+
/// </param>
230+
/// <returns>
231+
/// <c>true</c> if the instance is successfully created; otherwise, <c>false</c>.
232+
/// </returns>
172233
public static bool ").Append(_state.Settings.TryCreateFactoryMethodName).Append("(");
173234

174235
_sb.RenderArgumentsWithType(fieldsAndProperties, @"
@@ -199,6 +260,21 @@ private void GenerateValidateMethod()
199260

200261
_sb.Append(@"
201262
263+
/// <summary>
264+
/// Validates the values and creates an instance of type ").AppendTypeForXmlComment(_state).Append(@" if validation is successful.
265+
/// </summary>");
266+
267+
for (var i = 0; i < fieldsAndProperties.Count; i++)
268+
{
269+
var memberInfo = fieldsAndProperties[i];
270+
271+
_sb.Append(@"
272+
/// <param name=""").Append(memberInfo.ArgumentName).Append(@""">The value to be used for object creation.</param>");
273+
}
274+
275+
_sb.Append(@"
276+
/// <param name=""obj"">The created object if validation is successful, otherwise <c>null</c>.</param>
277+
/// <returns>A validation error if validation fails; otherwise, <c>null</c>.</returns>
202278
public static ").AppendTypeFullyQualified(_state.ValidationError).Append("? Validate(");
203279

204280
_sb.RenderArgumentsWithType(fieldsAndProperties, @"
@@ -350,6 +426,9 @@ private void GenerateConstructor()
350426

351427
_sb.Append(@"
352428
429+
/// <summary>
430+
/// Initializes a new instance of the ").AppendTypeForXmlComment(_state).Append(@" type.
431+
/// </summary>
353432
").RenderAccessModifier(_state.Settings.ConstructorAccessModifier).Append(" ").Append(_state.Name).Append("(");
354433

355434
_sb.RenderArgumentsWithType(fieldsAndProperties, prefix: @"

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ComplexValueObjectJsonCodeGenerator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ namespace ").Append(_type.Namespace).Append(@";
4040
[global::System.Text.Json.Serialization.JsonConverterAttribute(typeof(JsonConverterFactory))]
4141
partial ").AppendTypeKind(_type).Append(" ").Append(_type.Name).Append(@"
4242
{
43+
/// <summary>
44+
/// JSON converter for ").AppendTypeForXmlComment(_type).Append(@".
45+
/// </summary>
4346
public sealed class JsonConverter : global::System.Text.Json.Serialization.JsonConverter<").AppendTypeFullyQualified(_type).Append(@">
4447
{");
4548

@@ -60,6 +63,9 @@ public sealed class JsonConverter : global::System.Text.Json.Serialization.JsonC
6063

6164
_sb.Append(@"
6265
66+
/// <summary>
67+
/// Initializes JSON converter for ").AppendTypeForXmlComment(_type).Append(@".
68+
/// </summary>
6369
public JsonConverter(global::System.Text.Json.JsonSerializerOptions options)
6470
{
6571
if(options is null)
@@ -311,6 +317,9 @@ public override void Write(global::System.Text.Json.Utf8JsonWriter writer, ").Ap
311317
}
312318
}
313319
320+
/// <summary>
321+
/// JSON converter factory for ").AppendTypeForXmlComment(_type).Append(@".
322+
/// </summary>
314323
public class JsonConverterFactory : global::System.Text.Json.Serialization.JsonConverterFactory
315324
{
316325
/// <inheritdoc />

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ComplexValueObjectMessagePackCodeGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ namespace ").Append(_type.Namespace).Append(@";
6565
[global::MessagePack.MessagePackFormatter(typeof(ValueObjectMessagePackFormatter))]
6666
partial ").AppendTypeKind(_type).Append(" ").Append(_type.Name).Append(@"
6767
{
68+
/// <summary>
69+
/// MassagePack formatter for ").AppendTypeForXmlComment(_type).Append(@".
70+
/// </summary>
6871
public sealed class ValueObjectMessagePackFormatter : global::MessagePack.Formatters.IMessagePackFormatter<").AppendTypeFullyQualifiedNullAnnotated(_type).Append(@">
6972
{
7073
/// <inheritdoc />

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ComplexValueObjectNewtonsoftJsonCodeGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ namespace ").Append(_type.Namespace).Append(@";
3939
[global::Newtonsoft.Json.JsonConverterAttribute(typeof(ValueObjectNewtonsoftJsonConverter))]
4040
partial ").AppendTypeKind(_type).Append(" ").Append(_type.Name).Append(@"
4141
{
42+
/// <summary>
43+
/// JSON converter for ").AppendTypeForXmlComment(_type).Append(@".
44+
/// </summary>
4245
public sealed class ValueObjectNewtonsoftJsonConverter : global::Newtonsoft.Json.JsonConverter
4346
{
4447
private static readonly global::System.Type _type = typeof(").AppendTypeFullyQualified(_type).Append(@");

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/KeyedValueObjectCodeGenerator.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ private void GenerateValueObject(CancellationToken cancellationToken)
103103
{
104104
_sb.Append(@"
105105
106+
/// <summary>
107+
/// Default instance of ").AppendTypeForXmlComment(_state).Append(@".
108+
/// </summary>
106109
public static readonly ").AppendTypeFullyQualified(_state).Append(" ").Append(_state.Settings.DefaultInstancePropertyName).Append(" = default;");
107110
}
108111

@@ -272,7 +275,15 @@ private void GenerateConversionFromKey(bool emptyStringYieldsNull)
272275
private void GenerateCreateMethod(bool allowNullOutput, bool emptyStringYieldsNull)
273276
{
274277
_sb.Append(@"
275-
");
278+
/// <summary>
279+
/// Creates an instance of the type ").AppendTypeForXmlComment(_state).Append(@" from the provided value,
280+
/// performing validation during the process.
281+
/// </summary>
282+
/// <param name=""").Append(_state.KeyMember.ArgumentName).Append(@""">The value to create the object from.</param>
283+
/// <returns>An instance of ").AppendTypeForXmlComment(_state).Append(@" if validation is successful.</returns>
284+
/// <exception cref=""System.ComponentModel.DataAnnotations.ValidationException"">
285+
/// Thrown if the provided value does not pass validation.
286+
/// </exception>");
276287

277288
// If emptyStringYieldsNull=true then an empty-string-argument (i.e. not null) will lead to null as return value,
278289
// that's why we cannot use the NotNullIfNotNullAttribute.
@@ -298,13 +309,36 @@ private void GenerateTryCreateMethod(bool allowNullOutput, bool emptyStringYield
298309
{
299310
_sb.Append(@"
300311
312+
/// <summary>
313+
/// Tries to create an instance of the type ").AppendTypeForXmlComment(_state).Append(@" based on provided value.
314+
/// </summary>
315+
/// <param name=""").Append(_state.KeyMember.ArgumentName).Append(@""">The value to be used for object creation.</param>
316+
/// <param name=""obj"">
317+
/// When this method returns, contains the created object if the operation succeeded; otherwise, it will be <c>null</c> or default.
318+
/// </param>
319+
/// <returns>
320+
/// Returns <c>true</c> if the object was successfully created; otherwise, returns <c>false</c>.
321+
/// </returns>
301322
public static bool ").Append(_state.Settings.TryCreateFactoryMethodName).Append("(").RenderArgumentWithType(_state.KeyMember, useNullableTypes: allowNullOutput).Append(emptyStringYieldsNull ? "," : ", [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]").Append(" out ").AppendTypeFullyQualifiedNullAnnotated(_state).Append(@" obj)
302323
{
303324
return ").Append(_state.Settings.TryCreateFactoryMethodName).Append("(").RenderArgument(_state.KeyMember).Append(@", out obj, out _);
304325
}");
305326

306327
_sb.Append(@"
307328
329+
/// <summary>
330+
/// Tries to create an instance of the type ").AppendTypeForXmlComment(_state).Append(@" based on provided value.
331+
/// </summary>
332+
/// <param name=""").Append(_state.KeyMember.ArgumentName).Append(@""">The value to be used for object creation.</param>
333+
/// <param name=""obj"">
334+
/// When this method returns, contains the created object if the operation succeeded; otherwise, it will be <c>null</c> or default.
335+
/// </param>
336+
/// <param name=""validationError"">
337+
/// When the method returns, contains the validation error if the creation or validation failed; otherwise, it will be <c>null</c>.
338+
/// </param>
339+
/// <returns>
340+
/// Returns <c>true</c> if the object was successfully created; otherwise, returns <c>false</c>.
341+
/// </returns>
308342
public static bool ").Append(_state.Settings.TryCreateFactoryMethodName).Append(@"(
309343
").RenderArgumentWithType(_state.KeyMember, useNullableTypes: allowNullOutput).Append(@",
310344
").Append(emptyStringYieldsNull ? null : "[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] ").Append("out ").AppendTypeFullyQualifiedNullAnnotated(_state).Append(@" obj,
@@ -322,6 +356,15 @@ private void GenerateValidateMethod(bool allowNullKeyMemberInput, bool allowNull
322356

323357
_sb.Append(@"
324358
359+
/// <summary>
360+
/// Validates the provided value and attempts to create an instance of ").AppendTypeForXmlComment(_state).Append(@".
361+
/// </summary>
362+
/// <param name=""").Append(_state.KeyMember.ArgumentName).Append(@""">The value to validate.</param>
363+
/// <param name=""provider"">The format provider for parsing or validation, if applicable.</param>
364+
/// <param name=""obj"">When the method returns, contains the created instance of type ").AppendTypeForXmlComment(_state).Append(@" if validation succeeds; otherwise, <c>null</c>.</param>
365+
/// <returns>
366+
/// A ").AppendTypeForXmlComment(_state.ValidationError).Append(@" representing the validation error if validation fails; otherwise, <c>null</c>.
367+
/// </returns>
325368
public static ").AppendTypeFullyQualified(_state.ValidationError).Append("? Validate(").RenderArgumentWithType(_state.KeyMember, useNullableTypes: allowNullKeyMemberInput).Append(", global::System.IFormatProvider? ").AppendEscaped(providerArgumentName).Append(", out ").AppendTypeFullyQualifiedNullAnnotated(_state).Append(@" obj)
326369
{");
327370

@@ -421,6 +464,9 @@ private void GenerateConstructor()
421464
{
422465
_sb.Append(@"
423466
467+
/// <summary>
468+
/// Initializes a new instance of the ").AppendTypeForXmlComment(_state).Append(@" type.
469+
/// </summary>
424470
").RenderAccessModifier(_state.Settings.ConstructorAccessModifier).Append(" ").Append(_state.Name).Append("(").RenderArgumentWithType(_state.KeyMember).Append(@")
425471
{
426472
ValidateConstructorArguments(").RenderArgument(_state.KeyMember, "ref ").Append(@");

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ValueObjectSourceGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Thinktecture.CodeAnalysis.ValueObjects;
66
public sealed class ValueObjectSourceGenerator : ThinktectureSourceGeneratorBase, IIncrementalGenerator
77
{
88
public ValueObjectSourceGenerator()
9-
: base(15_000)
9+
: base(18_000)
1010
{
1111
}
1212

0 commit comments

Comments
 (0)