Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add generic support on RegisterCustomType() #1

Merged
merged 4 commits into from
Jun 19, 2018

Conversation

enginekit
Copy link

@enginekit enginekit commented Apr 30, 2018

add generic support on RegisterCustomType()

      JSON.RegisterCustomType<Point, List<object>>(
         //since we know that our point will be serialized to list of objects
         pt => string.Format("[{0},{1}]", pt.x, pt.y),
         (l, cb) =>
         {
             return new Point() { x = Convert.ToInt32(l[0]), y = Convert.ToSingle(l[1]) };
         });
    //
    JSON.RegisterCustomType<Complex, List<object>>(
        //since we know that our complex type will be serialized to list of objects
        c => string.Format("[{0},{1}]", c.i, JSON.ToJSON(c.l)),
        (l, cb) =>
        {
            return new Complex() { i = Convert.ToInt32(l[0]), l = (List<Point[]>)cb(l[1], typeof(List<Point[]>)) };
        });

https://github.com/enginekit/fastJSON/blob/f100fcd5b188877351fbb798ca9a73fa01d69edd/UnitTests/Tests.cs#L1939

@enginekit enginekit changed the title Dev1 add generic support on RegisterCustomType() Apr 30, 2018
@gekailin gekailin merged commit 12eb099 into gekailin:master Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants