Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Proposal] Add parameters to change the name of the properties generated by KeyValuePairConverter #3016

Open
Pretasoc opened this issue Feb 6, 2025 · 0 comments

Comments

@Pretasoc
Copy link

Pretasoc commented Feb 6, 2025

It would be nice, if we could add a constructor to KeyValuePairConverter so we can specify alternate names for Key and Value by using the Parameter property of the JsonConverterAttribute.

Consider this example

public class Student {}
public class Grade {}

[JsonArray(ItemConverterType = typeof(KeyValuePairConverter), ItemConverterParameters = new object[]{"Student", "Grade"})]
public class GradeDictionary : Dictionary<Student, Grade>{}

public class Course
{

    public GradeDictionary  Grades { get; } = new();
}

With the change we would get

{
    "Grades": [
        {
            "Student": {...},
            "Grade": {...}
        },
        ...

    ]
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant