Skip to content

add generic support on RegisterCustomType()#1

Merged
gekailin merged 4 commits intogekailin:masterfrom
enginekit:dev1
Jun 19, 2018
Merged

add generic support on RegisterCustomType()#1
gekailin merged 4 commits intogekailin:masterfrom
enginekit:dev1

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

Comments