Skip to content

Commit

Permalink
working on sourcegenertor
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasnordqvist committed Nov 10, 2024
1 parent 62fe728 commit 719be05
Show file tree
Hide file tree
Showing 13 changed files with 577 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

namespace DotNetThoughts.FartingUnicorn
namespace DotNetThoughts.FartingUnicorn
{
[System.AttributeUsage(System.AttributeTargets.Class)]
public class CreateMapperAttribute : System.Attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,145 @@
using System.Text.Json;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Benchmarks.UserProfile> MapToUserProfile(JsonElement jsonElement)
public static Result<FartingUnicorn.Benchmarks.UserProfile> MapToFartingUnicorn_Benchmarks_UserProfile(JsonElement jsonElement, string[] path = null)
{
var result = new FartingUnicorn.Benchmarks.UserProfile();
return Result<FartingUnicorn.Benchmarks.UserProfile>.Ok(result);
/*object*/
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Benchmarks.UserProfile>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
}
var obj = new FartingUnicorn.Benchmarks.UserProfile();

Result<Unit> compositeResult = UnitResult.Ok;
var isNamePropertyDefined = jsonElement.TryGetProperty("Name", out var jsonNameProperty);
if (isNamePropertyDefined)
{
// String
var mapResult = MapString(jsonNameProperty, /*mapperOptions,*/ [.. path, Name]);
if (mapResult.Success)
{
obj.Name = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
var isAgePropertyDefined = jsonElement.TryGetProperty("Age", out var jsonAgeProperty);
if (isAgePropertyDefined)
{
// Int32
if (mapResult.Success)
{
obj.Age = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
var isIsSubscribedPropertyDefined = jsonElement.TryGetProperty("IsSubscribed", out var jsonIsSubscribedProperty);
if (isIsSubscribedPropertyDefined)
{
// Boolean
if (mapResult.Success)
{
obj.IsSubscribed = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
var isCoursesPropertyDefined = jsonElement.TryGetProperty("Courses", out var jsonCoursesProperty);
if (isCoursesPropertyDefined)
{
//
if (mapResult.Success)
{
obj.Courses = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
var isPetPropertyDefined = jsonElement.TryGetProperty("Pet", out var jsonPetProperty);
if (isPetPropertyDefined)
{
// Pet
if (mapResult.Success)
{
obj.Pet = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
var isIsGayPropertyDefined = jsonElement.TryGetProperty("IsGay", out var jsonIsGayProperty);
if (isIsGayPropertyDefined)
{
// Nullable
if (mapResult.Success)
{
obj.IsGay = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
var isFavoritePetPropertyDefined = jsonElement.TryGetProperty("FavoritePet", out var jsonFavoritePetProperty);
if (isFavoritePetPropertyDefined)
{
// Pet
if (mapResult.Success)
{
obj.FavoritePet = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
if(!compositeResult.Success)
{
return Result<FartingUnicorn.Benchmarks.UserProfile>.Error(compositeResult.Errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Benchmarks.UserProfile>.Ok(obj);
}
throw new NotImplementedException();
}
}
2 changes: 1 addition & 1 deletion FartingUnicorn.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public async Task<UserProfile> FartingGeneratedDeserialization()
{
_jsonStream.Seek(0, SeekOrigin.Begin);
using var json = await JsonDocument.ParseAsync(_jsonStream);
return FartingUnicorn.Generated.Mappers.MapToUserProfile(json.RootElement).ValueOrThrow();
return FartingUnicorn.Generated.Mappers.MapToFartingUnicorn_Benchmarks_UserProfile(json.RootElement).ValueOrThrow();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

namespace DotNetThoughts.FartingUnicorn
namespace DotNetThoughts.FartingUnicorn
{
[System.AttributeUsage(System.AttributeTargets.Class)]
public class CreateMapperAttribute : System.Attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,49 @@
using System.Text.Json;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost> MapToBlogPost(JsonElement jsonElement)
public static Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_ReferenceType_NonNullableNonOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
{
var result = new FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost();
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost>.Ok(result);
/*object*/
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
}
var obj = new FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost();

Result<Unit> compositeResult = UnitResult.Ok;
var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty);
if (isTitlePropertyDefined)
{
// String
var mapResult = MapString(jsonTitleProperty, /*mapperOptions,*/ [.. path, Title]);
if (mapResult.Success)
{
obj.Title = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
if(!compositeResult.Success)
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost>.Error(compositeResult.Errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableNonOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using DotNetThoughts.Results;
using System.Text.Json;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_ReferenceType_NonNullableOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
{
/*object*/
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
}
var obj = new FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost();

Result<Unit> compositeResult = UnitResult.Ok;
var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty);
if (isTitlePropertyDefined)
{
// Option
if (mapResult.Success)
{
obj.Title = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
if(!compositeResult.Success)
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost>.Error(compositeResult.Errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NonNullableOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using DotNetThoughts.Results;
using System.Text.Json;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_ReferenceType_NullableOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
{
/*object*/
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
}
var obj = new FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost();

Result<Unit> compositeResult = UnitResult.Ok;
var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty);
if (isTitlePropertyDefined)
{
// Option
if (mapResult.Success)
{
obj.Title = mapResult.Value;
}
else
{
compositeResult = compositeResult.Or(mapResult);
}
}
else
{
}
if(!compositeResult.Success)
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost>.Error(compositeResult.Errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.ReferenceType.NullableOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Loading

0 comments on commit 719be05

Please sign in to comment.