-Code reformat
This commit is contained in:
+43
-43
@@ -6,51 +6,51 @@ using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeConstructorHandling
|
||||
{
|
||||
#region Types
|
||||
public class Website
|
||||
public class DeserializeConstructorHandling
|
||||
{
|
||||
public string Url { get; set; }
|
||||
|
||||
private Website()
|
||||
{
|
||||
}
|
||||
|
||||
public Website(Website website)
|
||||
{
|
||||
if (website == null)
|
||||
throw new ArgumentNullException("website");
|
||||
|
||||
Url = website.Url;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
string json = @"{'Url':'http://www.google.com'}";
|
||||
|
||||
try
|
||||
{
|
||||
JsonConvert.DeserializeObject<Website>(json);
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
// Value cannot be null.
|
||||
// Parameter name: website
|
||||
}
|
||||
|
||||
Website website = JsonConvert.DeserializeObject<Website>(json, new JsonSerializerSettings
|
||||
#region Types
|
||||
public class Website
|
||||
{
|
||||
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
|
||||
});
|
||||
public string Url { get; set; }
|
||||
|
||||
Console.WriteLine(website.Url);
|
||||
// http://www.google.com
|
||||
#endregion
|
||||
private Website()
|
||||
{
|
||||
}
|
||||
|
||||
public Website(Website website)
|
||||
{
|
||||
if (website == null)
|
||||
throw new ArgumentNullException("website");
|
||||
|
||||
Url = website.Url;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
string json = @"{'Url':'http://www.google.com'}";
|
||||
|
||||
try
|
||||
{
|
||||
JsonConvert.DeserializeObject<Website>(json);
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
// Value cannot be null.
|
||||
// Parameter name: website
|
||||
}
|
||||
|
||||
Website website = JsonConvert.DeserializeObject<Website>(json, new JsonSerializerSettings
|
||||
{
|
||||
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
|
||||
});
|
||||
|
||||
Console.WriteLine(website.Url);
|
||||
// http://www.google.com
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user