From d00de3f675d8a36d5118e61ff6026be396962400 Mon Sep 17 00:00:00 2001 From: Mattias Nordqvist Date: Sun, 10 Nov 2024 18:05:35 +0100 Subject: [PATCH] . --- ...pe.NullableNonOptional_Tests.BlogPost.g.cs | 10 +++- ...NonNullableNonOptional_Tests.BlogPost.g.cs | 58 ------------------- ...pe.NonNullableOptional_Tests.BlogPost.g.cs | 58 ------------------- ...pe.NullableNonOptional_Tests.BlogPost.g.cs | 58 ------------------- ...eType.NullableOptional_Tests.BlogPost.g.cs | 58 ------------------- MapperGenerator/MapperGenerator.cs | 5 +- 6 files changed, 13 insertions(+), 234 deletions(-) delete mode 100644 FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost.g.cs delete mode 100644 FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost.g.cs delete mode 100644 FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableNonOptional_Tests.BlogPost.g.cs delete mode 100644 FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost.g.cs diff --git a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost.g.cs b/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost.g.cs index 82f02d2..112bbba 100644 --- a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost.g.cs +++ b/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost.g.cs @@ -24,11 +24,19 @@ public static partial class Mappers var isIsDraftPropertyDefined = jsonElement.TryGetProperty("IsDraft", out var jsonIsDraftProperty); if (isIsDraftPropertyDefined) { - // type = Nullable, isOption = False, isNullable = True + // type = Boolean, isOption = False, isNullable = True if (jsonIsDraftProperty.ValueKind == JsonValueKind.Null) { errors.Add(new RequiredValueMissingError([.. path, "IsDraft"])); } + else if (jsonIsDraftProperty.ValueKind == JsonValueKind.True || jsonIsDraftProperty.ValueKind == JsonValueKind.False) + { + obj.IsDraft = jsonIsDraftProperty.GetBoolean(); + } + else + { + errors.Add(new ValueHasWrongTypeError([.. path, "IsDraft"], "Boolean", jsonIsDraftProperty.ValueKind.ToString())); + } } else { diff --git a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost.g.cs b/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost.g.cs deleted file mode 100644 index 341da47..0000000 --- a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost.g.cs +++ /dev/null @@ -1,58 +0,0 @@ -using DotNetThoughts.Results; -using System.Text.Json; - -namespace FartingUnicorn.Generated; - -public static partial class Mappers -{ - public static Result MapToFartingUnicorn_Tests_SingleField_ReferenceType_NonNullableNonOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null) - { - if(path is null) - { - path = ["$"]; - } - /*object*/ - { - if (jsonElement.ValueKind != JsonValueKind.Object) - { - return Result.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString())); - } - } - var obj = new FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost(); - - List errors = new(); - var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty); - if (isTitlePropertyDefined) - { - // type = String, isOption = False, isNullable = False - if (jsonTitleProperty.ValueKind == JsonValueKind.Null) - { - errors.Add(new RequiredValueMissingError([.. path, "Title"])); - } - else if (jsonTitleProperty.ValueKind == JsonValueKind.String) - { - obj.Title = jsonTitleProperty.GetString(); - } - else - { - errors.Add(new ValueHasWrongTypeError([.. path, "Title"], "String", jsonTitleProperty.ValueKind.ToString())); - } - } - else - { - errors.Add(new RequiredPropertyMissingError([.. path, "Title"])); - } - if(errors.Any()) - { - return Result.Error(errors); - } - if(false)/*check if is option*/ - { - } - else - { - return Result.Ok(obj); - } - throw new NotImplementedException(); - } -} diff --git a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost.g.cs b/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost.g.cs deleted file mode 100644 index 3ba5d24..0000000 --- a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost.g.cs +++ /dev/null @@ -1,58 +0,0 @@ -using DotNetThoughts.Results; -using System.Text.Json; - -namespace FartingUnicorn.Generated; - -public static partial class Mappers -{ - public static Result MapToFartingUnicorn_Tests_SingleField_ReferenceType_NonNullableOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null) - { - if(path is null) - { - path = ["$"]; - } - /*object*/ - { - if (jsonElement.ValueKind != JsonValueKind.Object) - { - return Result.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString())); - } - } - var obj = new FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost(); - - List errors = new(); - var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty); - if (isTitlePropertyDefined) - { - // type = String, isOption = True, isNullable = False - if (jsonTitleProperty.ValueKind == JsonValueKind.Null) - { - obj.Title = new None(); - } - else if (jsonTitleProperty.ValueKind == JsonValueKind.String) - { - obj.Title = new Some(jsonTitleProperty.GetString()); - } - else - { - errors.Add(new ValueHasWrongTypeError([.. path, "Title"], "String", jsonTitleProperty.ValueKind.ToString())); - } - } - else - { - errors.Add(new RequiredPropertyMissingError([.. path, "Title"])); - } - if(errors.Any()) - { - return Result.Error(errors); - } - if(false)/*check if is option*/ - { - } - else - { - return Result.Ok(obj); - } - throw new NotImplementedException(); - } -} diff --git a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableNonOptional_Tests.BlogPost.g.cs b/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableNonOptional_Tests.BlogPost.g.cs deleted file mode 100644 index 3c02f5f..0000000 --- a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableNonOptional_Tests.BlogPost.g.cs +++ /dev/null @@ -1,58 +0,0 @@ -using DotNetThoughts.Results; -using System.Text.Json; - -namespace FartingUnicorn.Generated; - -public static partial class Mappers -{ - public static Result MapToFartingUnicorn_Tests_SingleField_ReferenceType_NullableNonOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null) - { - if(path is null) - { - path = ["$"]; - } - /*object*/ - { - if (jsonElement.ValueKind != JsonValueKind.Object) - { - return Result.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString())); - } - } - var obj = new FartingUnicorn.Tests.SingleField.ReferenceType.NullableNonOptional_Tests.BlogPost(); - - List errors = new(); - var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty); - if (isTitlePropertyDefined) - { - // type = String, isOption = False, isNullable = True - if (jsonTitleProperty.ValueKind == JsonValueKind.Null) - { - errors.Add(new RequiredValueMissingError([.. path, "Title"])); - } - else if (jsonTitleProperty.ValueKind == JsonValueKind.String) - { - obj.Title = jsonTitleProperty.GetString(); - } - else - { - errors.Add(new ValueHasWrongTypeError([.. path, "Title"], "String", jsonTitleProperty.ValueKind.ToString())); - } - } - else - { - obj.Title = null; - } - if(errors.Any()) - { - return Result.Error(errors); - } - if(false)/*check if is option*/ - { - } - else - { - return Result.Ok(obj); - } - throw new NotImplementedException(); - } -} diff --git a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost.g.cs b/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost.g.cs deleted file mode 100644 index 384009a..0000000 --- a/FartingUnicorn.Tests/Generated/MapperGenerator/MapperGenerator.MapperGenerator/Mapper.FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost.g.cs +++ /dev/null @@ -1,58 +0,0 @@ -using DotNetThoughts.Results; -using System.Text.Json; - -namespace FartingUnicorn.Generated; - -public static partial class Mappers -{ - public static Result MapToFartingUnicorn_Tests_SingleField_ReferenceType_NullableOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null) - { - if(path is null) - { - path = ["$"]; - } - /*object*/ - { - if (jsonElement.ValueKind != JsonValueKind.Object) - { - return Result.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString())); - } - } - var obj = new FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost(); - - List errors = new(); - var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty); - if (isTitlePropertyDefined) - { - // type = String, isOption = True, isNullable = True - if (jsonTitleProperty.ValueKind == JsonValueKind.Null) - { - obj.Title = new None(); - } - else if (jsonTitleProperty.ValueKind == JsonValueKind.String) - { - obj.Title = new Some(jsonTitleProperty.GetString()); - } - else - { - errors.Add(new ValueHasWrongTypeError([.. path, "Title"], "String", jsonTitleProperty.ValueKind.ToString())); - } - } - else - { - obj.Title = null; - } - if(errors.Any()) - { - return Result.Error(errors); - } - if(false)/*check if is option*/ - { - } - else - { - return Result.Ok(obj); - } - throw new NotImplementedException(); - } -} diff --git a/MapperGenerator/MapperGenerator.cs b/MapperGenerator/MapperGenerator.cs index 2df4a0c..66bb5a7 100644 --- a/MapperGenerator/MapperGenerator.cs +++ b/MapperGenerator/MapperGenerator.cs @@ -242,7 +242,10 @@ static bool IsSyntaxTargetForGeneration(SyntaxNode node) : ((INamedTypeSymbol)p.Type).TypeArguments.First().Name; var isNullable = t.IsNullable(); - + if (t.IsNullableValueType()) + { + tName = ((INamedTypeSymbol)p.Type).TypeArguments.First().Name; + } properties.Add(new PropertyToGenerateMapperFor(p.Name, tName, isOptions, isNullable)); } }