Code Monkey home page Code Monkey logo

jsonmergepatch's People

Contributors

dependabot[bot] avatar ladeak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

colgreen

jsonmergepatch's Issues

DateOnly type support

Hi,

Our ASP.NET Core Controller projects are targeting .NET 6, and our DTO types make use of System.DateOnly (which is new to .NET 6)

The source generator produces wrapper properties like so for DateOnly typed properties:

private System.Nullable<LaDeak.JsonMergePatch.Generated.SafeSystem.DateOnlyWrapped> _dateOfBirth;
public System.Nullable<LaDeak.JsonMergePatch.Generated.SafeSystem.DateOnlyWrapped> DateOfBirth
{
    get { return _dateOfBirth; }
    set
    {
	Properties[11] = true;
	_dateOfBirth = value;
    }
}

If I am understanding correctly, I think DateOnly should be detected as a System type and not wrapped. I think that test occurs in GeneratedTypeFilter, here:

public static bool IsGeneratableType(ITypeSymbol typeInfo)
{
    bool generic = false;
    if (typeInfo is INamedTypeSymbol namedTypeInfo)
	generic = namedTypeInfo.IsGenericType;
    return typeInfo.SpecialType == SpecialType.None && !typeInfo.IsAnonymousType && !typeInfo.IsAbstract && !generic && !typeInfo.IsStatic && typeInfo.TypeKind != TypeKind.Enum;
}

The SpecialType enum doesn't contain a value for DateOnly, because the Microsoft.CodeAnalysis project is targeting .NetStandard 2.0, which doesn't include the DateOnly type.

I am not sure there is a nice solution here, but I guess extending that check for new types outside of .NetStandard 2.0 could work?

Compile error when IEnumerable<T> properties where T is a complex reference type

Let's say we have a DTO set-up like so:

[Patchable]
public class Client
{
    public string? Forename { get; set; }
    public IEnumerable<ClientAddress>? Addresses { get; set; }
}

[Patchable]
public class ClientAddress
{
   public string? Line1 { get; set; }
   public string? City { get; set; }
}

The generated wrapper class code contains this line:

ApplyChanges()

            if (Properties[1])
                input.Addresses = Addresses;

Which results in the following compiler error:

CS0266	Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<LaDeak.JsonMergePatch.Generated.SafeFoo.ClientAddressWrapped>' to 'System.Collections.Generic.IEnumerable<Foo.ClientAddress>'. An explicit conversion exists (are you missing a cast?)

I.e., ClientAddressWrapped is a sub-type of ClientAddress, and therefore a list or IEnumerable of ClientAddressWrapped can be cast to ClientAddress (as the lists contain references/pointers to the reference types on the heap), but only as an explicit cast.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.