निम्नलिखित कोड एक अपवाद फेंक देगा:deserialize json.net साथ अशक्त regex संपत्ति
class SimpleClassWithRegex
{
public Regex RegProp { get; set; }
}
[TestMethod]
public void RegexTest()
{
string json = JsonConvert.SerializeObject(new SimpleClassWithRegex {RegProp = null});
// json = {"RegProp":null}
SimpleClassWithRegex obj = JsonConvert.DeserializeObject<SimpleClassWithRegex>(json);
//Above line throws a JsonSerializationException
}
यह मेरे लिए अजीब व्यवहार की तरह लगता है, किसी को समझा सकता है क्यों यह एक बग नहीं है? या शायद एक कामकाज का सुझाव है? शून्य के स्थान पर Regex
ऑब्जेक्ट को इंस्टेंट करने से निश्चित रूप से इसे अपवाद फेंकने से रोक दिया जाएगा।
अपवाद का उत्पादन किया है:
Newtonsoft.Json.JsonSerializationException: Unexpected token when reading Regex. Path 'RegProp', line 1, position 15.
कामकाज के लिए बहुत बहुत धन्यवाद। मैं एक बग रिपोर्ट दर्ज करने में भी देखेंगे। –