How to serialize a Guid with C# without creating an object?
<p>I want my Guids to be serialized into a short form of Guid (<a href="http://www.singular.co.nz/2007/12/shortguid-a-shorter-and-url-friendly-guid-in-c-sharp/" rel="nofollow noreferrer">as seen here</a>). For full compatibility, I want the ShortGuid class to serialize into the short form, and not the long form.</p>

<p>I've tried <a href="https://msdn.microsoft.com/en-us/library/ty01x675(v=vs.110).aspx" rel="nofollow noreferrer">using custom serialization</a>, but I can't seem to make the whole object serialize into the short string, only into an object which contains the string. This is what I've tried:</p>

<pre><code>[Serializable]
public class ShortGuid : ISerializable
{
    public Guid Guid { get; }
    protected ShortGuid(SerializationInfo info, StreamingContext context)
    {
        Guid = Decode(info.GetString("Guid"));
    }

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("Guid", Encode(Guid));
    }
}
</code></pre>

<p>Which works, but if I serialize it:</p>

<pre><code>var guid = new ShortGuid(Guid.NewGuid());
var str = JsonConvert.Serialize(guid);
</code></pre>

<p>The serialized string I get looks like this:</p>

<pre><code>{ Guid: "xxxxxxxxxxxxxxxxxx" }
</code></pre>

<p>While the serialized string I WANT is just</p>

<pre><code>xxxxxxxxxxxxxxxxxx
</code></pre>

<p>I've turned everything around, but can't get this to work. How can this be done?</p>

<p>NOTE: I don't want this to work only on JsonConvert, this is only an example. I would like the class the always be serialized correctly.</p>