Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PM> Install-Package M31.FluentApi
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:

```xml
<PackageReference Include="M31.FluentApi" Version="1.11.0" PrivateAssets="all"/>
<PackageReference Include="M31.FluentApi" Version="1.12.0" PrivateAssets="all"/>
```

If you would like to examine the generated code, you may emit it by adding the following lines to your `csproj` file:
Expand Down Expand Up @@ -586,4 +586,4 @@ In particular, if your IDE visually indicates that there are errors in your code

This library is free. If you find it valuable and wish to express your support, please leave a star. You are kindly invited to contribute. If you see the possibility for enhancement, please create a GitHub issue and you will receive timely feedback.

Happy coding!
Happy coding!
4 changes: 3 additions & 1 deletion src/M31.FluentApi.Generator/CodeBuilding/Parameter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using M31.FluentApi.Generator.Commons;

namespace M31.FluentApi.Generator.CodeBuilding;

internal class Parameter : ICode
Expand All @@ -10,7 +12,7 @@ internal Parameter(
ParameterAnnotations? parameterAnnotations = null)
{
Type = type;
Name = name;
Name = CSharpKeywords.IsCSharpKeyword(name) ? $"@{name}" : name;
DefaultValue = defaultValue;
GenericTypeParameterPosition = genericTypeParameterPosition;
ParameterAnnotations = parameterAnnotations;
Expand Down
11 changes: 11 additions & 0 deletions src/M31.FluentApi.Generator/Commons/CSharpKeywords.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.CodeAnalysis.CSharp;

namespace M31.FluentApi.Generator.Commons;

internal static class CSharpKeywords
{
internal static bool IsCSharpKeyword(string name)
{
return SyntaxFacts.GetKeywordKind(name) != SyntaxKind.None;
}
}
2 changes: 1 addition & 1 deletion src/M31.FluentApi.Generator/M31.FluentApi.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<PackageVersion>1.11.0</PackageVersion>
<PackageVersion>1.12.0</PackageVersion>
<Authors>Kevin Schaal</Authors>
<Description>The generator package for M31.FluentAPI. Don't install this package explicitly, install M31.FluentAPI instead.</Description>
<PackageTags>fluentapi fluentbuilder fluentinterface fluentdesign fluent codegeneration</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <auto-generated/>
// This code was generated by the library M31.FluentAPI.
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#nullable enable

using System;

namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.Abstract.KeywordClass;

public class CreateStudent :
CreateStudent.ICreateStudent,
CreateStudent.IWithOperator,
CreateStudent.IWithClass,
CreateStudent.IWithVoid
{
private readonly Student student;

private CreateStudent()
{
student = new Student();
}

public static ICreateStudent InitialStep()
{
return new CreateStudent();
}

public static IWithClass WithOperator(string @operator)
{
CreateStudent createStudent = new CreateStudent();
createStudent.student.Operator = @operator;
return createStudent;
}

IWithClass IWithOperator.WithOperator(string @operator)
{
student.Operator = @operator;
return this;
}

IWithVoid IWithClass.WithClass(string @class)
{
student.Class = @class;
return this;
}

Student IWithVoid.WithVoid(int @void)
{
student.Void = @void;
return student;
}

public interface ICreateStudent : IWithOperator
{
}

public interface IWithOperator
{
IWithClass WithOperator(string @operator);
}

public interface IWithClass
{
IWithVoid WithClass(string @class);
}

public interface IWithVoid
{
Student WithVoid(int @void);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <auto-generated/>
// This code was generated by the library M31.FluentAPI.
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#nullable enable

using System;

namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.Abstract.KeywordClass;

public class CreateStudent :
CreateStudent.ICreateStudent,
CreateStudent.IWithOperator,
CreateStudent.IWithClass,
CreateStudent.IWithVoid
{
private readonly Student student;

private CreateStudent()
{
student = new Student();
}

public static ICreateStudent InitialStep()
{
return new CreateStudent();
}

public static IWithClass WithOperator(string @operator)
{
CreateStudent createStudent = new CreateStudent();
createStudent.student.Operator = @operator;
return createStudent;
}

IWithClass IWithOperator.WithOperator(string @operator)
{
student.Operator = @operator;
return this;
}

IWithVoid IWithClass.WithClass(string @class)
{
student.Class = @class;
return this;
}

Student IWithVoid.WithVoid(int @void)
{
student.Void = @void;
return student;
}

public interface ICreateStudent : IWithOperator
{
}

public interface IWithOperator
{
IWithClass WithOperator(string @operator);
}

public interface IWithClass
{
IWithVoid WithClass(string @class);
}

public interface IWithVoid
{
Student WithVoid(int @void);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Non-nullable member is uninitialized
#pragma warning disable CS8618
// ReSharper disable All

using System;
using M31.FluentApi.Attributes;

namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.Abstract.KeywordClass;

[FluentApi]
public class Student
{
[FluentMember(0)]
public string Operator { get; set; }

[FluentMember(1, "With{Name}")]
public string Class { get; set; }

[FluentMember(2)]
public int Void { get; set; }
}
1 change: 1 addition & 0 deletions src/M31.FluentApi.Tests/CodeGeneration/TestDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ internal class TestDataProvider : IEnumerable<object[]>
new object[] { "Abstract", "InheritedClassProtectedSetters", "Student|Person" },
new object[] { "Abstract", "InheritedRecord", "Student|Person" },
new object[] { "Abstract", "InternalClass", "Student" },
new object[] { "Abstract", "KeywordClass", "Student"},
new object[] { "Abstract", "NonGenericCollectionMemberClass", "Student" },
new object[] { "Abstract", "NullablePredicateAndCollectionClass", "Student" },
new object[] { "Abstract", "OneMemberClass", "Student" },
Expand Down
2 changes: 1 addition & 1 deletion src/M31.FluentApi/M31.FluentApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.11.0</PackageVersion>
<PackageVersion>1.12.0</PackageVersion>
<Authors>Kevin Schaal</Authors>
<Description>Generate fluent builders in C#.</Description>
<PackageTags>fluentapi fluentbuilder fluentinterface fluentdesign fluent codegeneration</PackageTags>
Expand Down
Loading