当前位置: 首页>>代码示例>>C#>>正文


C# JsonObjectContract.DefaultCreator方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Serialization.JsonObjectContract.DefaultCreator方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObjectContract.DefaultCreator方法的具体用法?C# JsonObjectContract.DefaultCreator怎么用?C# JsonObjectContract.DefaultCreator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Serialization.JsonObjectContract的用法示例。


在下文中一共展示了JsonObjectContract.DefaultCreator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:34,代码来源:JsonSerializerInternalReader.cs

示例2: CreateAndPopulateObject

    private object CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, string id)
    {
      object newObject = null;

      if (contract.UnderlyingType.IsInterface() || contract.UnderlyingType.IsAbstract())
        throw CreateSerializationException(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantated.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));

      if (contract.OverrideConstructor != null)
      {
        if (contract.OverrideConstructor.GetParameters().Length > 0)
          return CreateObjectFromNonDefaultConstructor(reader, contract, contract.OverrideConstructor, id);

        newObject = contract.OverrideConstructor.Invoke(null);
      }
      else if (contract.DefaultCreator != null &&
        (!contract.DefaultCreatorNonPublic || Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor || contract.ParametrizedConstructor == 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 constructor
        newObject = contract.DefaultCreator();
      }
      else if (contract.ParametrizedConstructor != null)
      {
        return CreateObjectFromNonDefaultConstructor(reader, contract, contract.ParametrizedConstructor, id);
      }

      if (newObject == null)
        throw CreateSerializationException(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, contract.UnderlyingType));

      PopulateObject(newObject, reader, contract, id);
      return newObject;
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:34,代码来源:JsonSerializerInternalReader.cs

示例3: CreateNewObject

        public object CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, string id, out bool createdFromNonDefaultConstructor)
        {
            object 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));

              if (objectContract.OverrideConstructor != null)
              {
            if (objectContract.OverrideConstructor.GetParameters().Length > 0)
            {
              createdFromNonDefaultConstructor = true;
              return CreateObjectFromNonDefaultConstructor(reader, objectContract, containerMember, objectContract.OverrideConstructor, id);
            }

            newObject = objectContract.OverrideConstructor.Invoke(null);
              }
              else if (objectContract.DefaultCreator != null &&
            (!objectContract.DefaultCreatorNonPublic || Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor || objectContract.ParametrizedConstructor == 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 constructor
            newObject = objectContract.DefaultCreator();
              }
              else if (objectContract.ParametrizedConstructor != null)
              {
            createdFromNonDefaultConstructor = true;
            return CreateObjectFromNonDefaultConstructor(reader, objectContract, containerMember, objectContract.ParametrizedConstructor, id);
              }

              if (newObject == null)
            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));

              createdFromNonDefaultConstructor = false;
              return newObject;
        }
开发者ID:rv192,项目名称:Fussen,代码行数:38,代码来源:JsonSerializerInternalReader.cs

示例4: CreateAndPopulateObject

    private object CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, string id)
    {
      object newObject = null;

      if (contract.UnderlyingType.IsInterface || contract.UnderlyingType.IsAbstract)
        throw new JsonSerializationException("Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantated.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));

      if (contract.DefaultCreator != null &&
        (!contract.DefaultCreatorNonPublic || Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
      {
        newObject = contract.DefaultCreator();
      }

      if (newObject != null)
      {
        PopulateObject(newObject, reader, contract, id);
        return newObject;
      }

      return CreateObjectFromNonDefaultConstructor(reader, contract, id);
    }
开发者ID:nathanpalmer,项目名称:ravendb,代码行数:21,代码来源:JsonSerializerInternalReader.cs

示例5: CreateNewObject

 public object CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, string id, out bool createdFromNonDefaultConstructor)
 {
   object obj = (object) null;
   if (TypeExtensions.IsInterface(objectContract.UnderlyingType) || TypeExtensions.IsAbstract(objectContract.UnderlyingType))
     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.", (IFormatProvider) CultureInfo.InvariantCulture, (object) objectContract.UnderlyingType));
   if (objectContract.OverrideConstructor != null)
   {
     if (objectContract.OverrideConstructor.GetParameters().Length > 0)
     {
       createdFromNonDefaultConstructor = true;
       return this.CreateObjectFromNonDefaultConstructor(reader, objectContract, containerMember, objectContract.OverrideConstructor, id);
     }
     else
       obj = objectContract.OverrideConstructor.Invoke((object[]) null);
   }
   else if (objectContract.DefaultCreator != null && (!objectContract.DefaultCreatorNonPublic || this.Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor || objectContract.ParametrizedConstructor == null))
     obj = objectContract.DefaultCreator();
   else if (objectContract.ParametrizedConstructor != null)
   {
     createdFromNonDefaultConstructor = true;
     return this.CreateObjectFromNonDefaultConstructor(reader, objectContract, containerMember, objectContract.ParametrizedConstructor, id);
   }
   if (obj == null)
     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.", (IFormatProvider) CultureInfo.InvariantCulture, (object) objectContract.UnderlyingType));
   createdFromNonDefaultConstructor = false;
   return obj;
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:27,代码来源:JsonSerializerInternalReader.cs


注:本文中的Newtonsoft.Json.Serialization.JsonObjectContract.DefaultCreator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。