// 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));
 }
Ejemplo n.º 2
0
        private object CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, string id)
        {
            object obj = 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.OverrideConstructor != null)
            {
                if (contract.OverrideConstructor.GetParameters().Length > 0)
                {
                    return(CreateObjectFromNonDefaultConstructor(reader, contract, contract.OverrideConstructor, id));
                }
                obj = contract.OverrideConstructor.Invoke(null);
            }
            else if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || base.Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
            {
                obj = contract.DefaultCreator();
            }
            else if (contract.ParametrizedConstructor != null)
            {
                return(CreateObjectFromNonDefaultConstructor(reader, contract, contract.ParametrizedConstructor, id));
            }
            if (obj == null)
            {
                throw new JsonSerializationException("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(obj, reader, contract, id);
            return(obj);
        }
Ejemplo n.º 3
0
        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));
        }
    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;
    }
Ejemplo n.º 5
0
        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;
        }
    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);
    }
Ejemplo n.º 7
0
 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;
 }