Skip to content

Commit

Permalink
Merge pull request #123 from leancodepl/feature/struct-dto
Browse files Browse the repository at this point in the history
Allow parsing `struct`s
  • Loading branch information
mishioo authored Dec 12, 2022
2 parents bbec17c + 13ba344 commit aafbe24
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `dotnet contracts-generate` global tool,
- Allow running the generator in check-only mode,
- _Invalid type_ analyzer,
- Enum members (`EnumValue`) have attributes.
- Enum members (`EnumValue`) have attributes,
- Support for `struct` members.

### Breaking changes

Expand Down
7 changes: 7 additions & 0 deletions examples/properties/inner_struct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class DTO
{
InnerDTO A { get; set; }
InnerDTO? B { get; set; }
}

public struct InnerDTO { }
4 changes: 4 additions & 0 deletions examples/properties/struct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public struct DTO
{
int A { get; set; }
}
1 change: 1 addition & 0 deletions examples/simple/struct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public struct DTO {}
19 changes: 19 additions & 0 deletions src/LeanCode.ContractsGenerator.Tests/ExampleBased/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,23 @@ public void Properties_with_binary_types()
.WithProperty("C", Array(Known(KnownType.Binary)))
.WithProperty("D", Map(Known(KnownType.Binary), Known(KnownType.Binary)));
}

[Fact]
public void Properties_inside_struct_types()
{
"properties/struct.cs"
.Compiles()
.WithDto("DTO")
.WithProperty("A", Known(KnownType.Int32));
}

[Fact]
public void Properties_with_struct_types()
{
"properties/inner_struct.cs"
.Compiles()
.WithDto("DTO")
.WithProperty("A", TypeRefExtensions.Internal("InnerDTO"))
.WithProperty("B", TypeRefExtensions.Internal("InnerDTO").Nullable());
}
}
9 changes: 9 additions & 0 deletions src/LeanCode.ContractsGenerator.Tests/ExampleBased/Simple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public void Simple_Dto()
.Dto("DTO");
}

[Fact]
public void Simple_Struct()
{
"simple/struct.cs"
.Compiles()
.WithSingle()
.Dto("DTO");
}

[Fact]
public void Simple_Enum()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private bool IsIgnored([System.Diagnostics.CodeAnalysis.NotNullWhen(false)] INam
{
return symbol is null ||
symbol.SpecialType == SpecialType.System_Object ||
symbol.SpecialType == SpecialType.System_ValueType ||
symbol.SpecialType == SpecialType.System_Enum ||
ErrorCodes.IsErrorCode(symbol) ||
contracts.Types.IsAttributeUsageType(symbol);
Expand Down

0 comments on commit aafbe24

Please sign in to comment.