Convert JSON.NET $type to __type

Converts a JSON.NET $type string to a WCF-compatible __type string.

JavaScript

var type = "MyNamespace.Domain.Entities.Person, MyNamespace.Domain";

var c, x, y, ns;

x = type.split(',')[0].split('.');
c = x[x.length - 1];
y = type.split(',')[0];
ns = y.substring(0, y.length - c.length - 1);

document.write(c + ":#" + ns);

// Now you can send:
// {
//    "__type": typeString
// }