Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Although I appreciate Rivers' answer I am really looking for a solution that ignores all expandable object converters automatically (like the DataContractJsonSerializer does) rather than building a custom JsonConverter for each offending class.</p> <p>I have found the following two solutions:</p> <ol> <li>Use the built in DataContractJsonSerializer instead (at the expense of some other conveniences of JSON.NET).</li> <li>Use a custom ExpandableObjectConverter (see below).</li> </ol> <p>Since the default ExpandableObjectConverter supports converting to/from string, JSON.NET is serializing the class with a string. To counteract this I have created my own expandable object converter which does not allow conversions to/from string.</p> <pre><code>Imports System.ComponentModel Public Class SerializableExpandableObjectConverter Inherits ExpandableObjectConverter Public Overrides Function CanConvertTo(context As System.ComponentModel.ITypeDescriptorContext, destinationType As System.Type) As Boolean If destinationType Is GetType(String) Then Return False Else Return MyBase.CanConvertTo(context, destinationType) End If End Function Public Overrides Function CanConvertFrom(context As System.ComponentModel.ITypeDescriptorContext, sourceType As System.Type) As Boolean If sourceType Is GetType(String) Then Return False Else Return MyBase.CanConvertFrom(context, sourceType) End If End Function End Class </code></pre> <p>Applying the above converter works flawlessly with JSON.NET and with the property grid control!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload