本文整理汇总了C#中Newtonsoft.Json.Serialization.JsonObjectContract.OverrideCreator方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObjectContract.OverrideCreator方法的具体用法?C# JsonObjectContract.OverrideCreator怎么用?C# JsonObjectContract.OverrideCreator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Serialization.JsonObjectContract
的用法示例。
在下文中一共展示了JsonObjectContract.OverrideCreator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewObject
// Token: 0x06000BDB RID: 3035
// RVA: 0x00046004 File Offset: 0x00044204
public object CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, string id, out bool createdFromNonDefaultCreator)
{
object obj = null;
if (objectContract.OverrideCreator != null)
{
if (objectContract.CreatorParameters.Count > 0)
{
createdFromNonDefaultCreator = true;
return this.CreateObjectUsingCreatorWithParameters(reader, objectContract, containerMember, objectContract.OverrideCreator, id);
}
obj = objectContract.OverrideCreator(new object[0]);
}
else if (objectContract.DefaultCreator != null && (!objectContract.DefaultCreatorNonPublic || this.Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor || objectContract.ParametrizedCreator == null))
{
obj = objectContract.DefaultCreator();
}
else if (objectContract.ParametrizedCreator != null)
{
createdFromNonDefaultCreator = true;
return this.CreateObjectUsingCreatorWithParameters(reader, objectContract, containerMember, objectContract.ParametrizedCreator, id);
}
if (obj != null)
{
createdFromNonDefaultCreator = false;
return obj;
}
if (!objectContract.IsInstantiable)
{
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.", CultureInfo.InvariantCulture, objectContract.UnderlyingType));
}
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unable to find a constructor to use for type {0}. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute.", CultureInfo.InvariantCulture, objectContract.UnderlyingType));
}
示例2: CreateNewObject
public object CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, string id, out bool createdFromNonDefaultCreator)
{
object newObject = null;
if (objectContract.OverrideCreator != null)
{
if (objectContract.CreatorParameters.Count > 0)
{
createdFromNonDefaultCreator = true;
return CreateObjectUsingCreatorWithParameters(reader, objectContract, containerMember, objectContract.OverrideCreator, id);
}
newObject = objectContract.OverrideCreator(new object[0]);
}
else if (objectContract.DefaultCreator != null &&
(!objectContract.DefaultCreatorNonPublic || Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor || objectContract.ParametrizedCreator == null))
{
// use the default constructor if it is...
// public
// non-public and the user has change constructor handling settings
// non-public and there is no other creator
newObject = objectContract.DefaultCreator();
}
else if (objectContract.ParametrizedCreator != null)
{
createdFromNonDefaultCreator = true;
return CreateObjectUsingCreatorWithParameters(reader, objectContract, containerMember, objectContract.ParametrizedCreator, id);
}
if (newObject == null)
{
if (!objectContract.IsInstantiable)
throw JsonSerializationException.Create(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.".FormatWith(CultureInfo.InvariantCulture, objectContract.UnderlyingType));
throw JsonSerializationException.Create(reader, "Unable to find a constructor to use for type {0}. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute.".FormatWith(CultureInfo.InvariantCulture, objectContract.UnderlyingType));
}
createdFromNonDefaultCreator = false;
return newObject;
}