You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A package reference will be added to your `csproj` file. Moreover, since this library provides code via source code generation, consumers of your project don't need the reference to `M31.FluentApi`. Therefore, it is recommended to use the `PrivateAssets` metadata tag:
//// <fluentReturns>A builder for setting the student's age.</fluentReturns>
453
+
[FluentMember(0)]
454
+
publicstringName { get; privateset; }
455
+
```
456
+
457
+
Using four slashes instead of three prevents the IDE from interpreting these comments as standard XML documentation for the member.
458
+
459
+
All `fluent`-prefixed tags are copied to the generated builder method and automatically transformed, e.g., `//// <fluentSummary>` becomes `/// <summary>` in the generated code.
460
+
461
+
For compounds, add the documentation comments to the first member of the compound only to avoid duplication:
462
+
463
+
```cs
464
+
//// <fluentSummary>
465
+
//// Sets the student's name.
466
+
//// </fluentSummary>
467
+
//// <fluentParam name="firstName">The student's first name.</fluentParam>
468
+
//// <fluentParam name="lastName">The student's last name.</fluentParam>
469
+
//// <fluentReturns>A builder for setting the student's age.</fluentReturns>
470
+
[FluentMember(0, "Named", 0)]
471
+
publicstringFirstName { get; privateset; }
472
+
473
+
[FluentMember(0, "Named", 1)]
474
+
publicstringLastName { get; privateset; }
475
+
```
476
+
477
+
If multiple methods are generated for a member, you can target a specific method by adding the `method` XML attribute to the documentation tags:
478
+
479
+
```cs
480
+
//// <fluentSummary method="InSemester">
481
+
//// Sets the student's current semester.
482
+
//// </fluentSummary>
483
+
//// <fluentParam method="InSemester" name="semester">The student's current semester.</fluentParam>
484
+
//// <fluentReturns method="InSemester">A builder for setting the student's city.</fluentReturns>
485
+
////
486
+
//// <fluentSummary method="WhoStartsUniversity">
487
+
//// Sets the student's semester to 0.
488
+
//// </fluentSummary>
489
+
//// <fluentReturns method="WhoStartsUniversity">A builder for setting the student's city.</fluentReturns>
490
+
[FluentMember(2, "InSemester")]
491
+
[FluentDefault("WhoStartsUniversity")]
492
+
publicintSemester { get; privateset; } =0;
493
+
```
494
+
495
+
To simplify adding documentation comments, a code action is available to generate the boilerplate for the selected member:
For reference, you can view the documented version of the `Student` class in [DocumentedStudent.cs](src/M31.FluentApi.Tests/CodeGeneration/TestClasses/DocumentedStudentClass/DocumentedStudent.cs). The corresponding generated code is located in [DocumentedStudent.g.cs](src/M31.FluentApi.Tests/CodeGeneration/TestClasses/DocumentedStudentClass/CreateDocumentedStudent.g.cs)
500
+
501
+
443
502
### Lambda pattern
444
503
445
504
Instances of Fluent API classes can be created and passed into methods of other classes using the lambda pattern. For example, given a `University` class that needs to be augmented with an `AddStudent` method, the following code demonstrates the lambda pattern:
0 commit comments