示例#1
0
        private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, string id)
        {
            Type objectType = contract.UnderlyingType;

            SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, GetFormatterConverter());

            bool exit = false;

            do
            {
                switch (reader.TokenType)
                {
                case JsonToken.PropertyName:
                    string memberName = reader.Value.ToString();
                    if (!reader.Read())
                    {
                        throw new JsonSerializationException("Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));
                    }

                    serializationInfo.AddValue(memberName, JToken.ReadFrom(reader));
                    break;

                case JsonToken.Comment:
                    break;

                case JsonToken.EndObject:
                    exit = true;
                    break;

                default:
                    throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
                }
            } while (!exit && reader.Read());

            if (contract.ISerializableCreator == null)
            {
                throw new JsonSerializationException("ISerializable type '{0}' does not have a valid constructor.".FormatWith(CultureInfo.InvariantCulture, objectType));
            }

            object createdObject = contract.ISerializableCreator(serializationInfo, Serializer.Context);

            if (id != null)
            {
                Serializer.ReferenceResolver.AddReference(this, id, createdObject);
            }

            // these are together because OnDeserializing takes an object but for an ISerializable the object is full created in the constructor
            contract.InvokeOnDeserializing(createdObject, Serializer.Context);
            contract.InvokeOnDeserialized(createdObject, Serializer.Context);

            return(createdObject);
        }
示例#2
0
        private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, string id)
        {
            Type underlyingType = contract.UnderlyingType;
            SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, GetFormatterConverter());
            bool flag = false;

            do
            {
                switch (reader.TokenType)
                {
                case JsonToken.PropertyName:
                {
                    string text = reader.Value.ToString();
                    if (!reader.Read())
                    {
                        throw new JsonSerializationException("Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, text));
                    }
                    serializationInfo.AddValue(text, JToken.ReadFrom(reader));
                    break;
                }

                case JsonToken.EndObject:
                    flag = true;
                    break;

                default:
                    throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);

                case JsonToken.Comment:
                    break;
                }
            }while (!flag && reader.Read());
            if (contract.ISerializableCreator == null)
            {
                throw new JsonSerializationException("ISerializable type '{0}' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present.".FormatWith(CultureInfo.InvariantCulture, underlyingType));
            }
            object obj = contract.ISerializableCreator(serializationInfo, base.Serializer.Context);

            if (id != null)
            {
                base.Serializer.ReferenceResolver.AddReference(this, id, obj);
            }
            contract.InvokeOnDeserializing(obj, base.Serializer.Context);
            contract.InvokeOnDeserialized(obj, base.Serializer.Context);
            return(obj);
        }
    private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, string id)
    {
      Type objectType = contract.UnderlyingType;

      SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, GetFormatterConverter());

      bool exit = false;
      do
      {
        switch (reader.TokenType)
        {
          case JsonToken.PropertyName:
            string memberName = reader.Value.ToString();
            if (!reader.Read())
              throw CreateSerializationException(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));

            serializationInfo.AddValue(memberName, JToken.ReadFrom(reader));
            break;
          case JsonToken.Comment:
            break;
          case JsonToken.EndObject:
            exit = true;
            break;
          default:
            throw CreateSerializationException(reader, "Unexpected token when deserializing object: " + reader.TokenType);
        }
      } while (!exit && reader.Read());

      if (contract.ISerializableCreator == null)
        throw CreateSerializationException(reader, "ISerializable type '{0}' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present.".FormatWith(CultureInfo.InvariantCulture, objectType));

      object createdObject = contract.ISerializableCreator(serializationInfo, Serializer.Context);

      if (id != null)
        Serializer.ReferenceResolver.AddReference(this, id, createdObject);

      // these are together because OnDeserializing takes an object but for an ISerializable the object is full created in the constructor
      contract.InvokeOnDeserializing(createdObject, Serializer.Context);
      contract.InvokeOnDeserialized(createdObject, Serializer.Context);

      return createdObject;
    }
    private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, string id)
    {
      Type objectType = contract.UnderlyingType;

      SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, GetFormatterConverter());

      bool exit = false;
      do
      {
        switch (reader.TokenType)
        {
          case JsonToken.PropertyName:
            string memberName = reader.Value.ToString();
            if (!reader.Read())
              throw new JsonSerializationException("Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));

            serializationInfo.AddValue(memberName, JToken.ReadFrom(reader));
            break;
          case JsonToken.EndObject:
            exit = true;
            break;
          default:
            throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
        }
      } while (!exit && reader.Read());

      if (contract.ISerializableCreator == null)
        throw new JsonSerializationException("ISerializable type '{0}' does not have a valid constructor.".FormatWith(CultureInfo.InvariantCulture, objectType));

      object createdObject = contract.ISerializableCreator(serializationInfo, Serializer.Context);

      if (id != null)
        Serializer.ReferenceResolver.AddReference(id, createdObject);

      contract.InvokeOnDeserializing(createdObject, Serializer.Context);
      contract.InvokeOnDeserialized(createdObject, Serializer.Context);

      return createdObject;
    }
    private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, string id)
    {
      Type objectType = contract.UnderlyingType;

      if (!JsonTypeReflector.FullyTrusted)
      {
        throw JsonSerializationException.Create(reader, @"Type '{0}' implements ISerializable but cannot be deserialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.
".FormatWith(CultureInfo.InvariantCulture, objectType));
      }

      SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, GetFormatterConverter());

      bool exit = false;
      do
      {
        switch (reader.TokenType)
        {
          case JsonToken.PropertyName:
            string memberName = reader.Value.ToString();
            if (!reader.Read())
              throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));

            serializationInfo.AddValue(memberName, JToken.ReadFrom(reader));
            break;
          case JsonToken.Comment:
            break;
          case JsonToken.EndObject:
            exit = true;
            break;
          default:
            throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + reader.TokenType);
        }
      } while (!exit && reader.Read());

      if (contract.ISerializableCreator == null)
        throw JsonSerializationException.Create(reader, "ISerializable type '{0}' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present.".FormatWith(CultureInfo.InvariantCulture, objectType));

      object createdObject = contract.ISerializableCreator(serializationInfo, Serializer.Context);

      if (id != null)
        Serializer.ReferenceResolver.AddReference(this, id, createdObject);

      // these are together because OnDeserializing takes an object but for an ISerializable the object is fully created in the constructor
      contract.InvokeOnDeserializing(createdObject, Serializer.Context);
      contract.InvokeOnDeserialized(createdObject, Serializer.Context);

      return createdObject;
    }
 private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, string id)
 {
   Type underlyingType = contract.UnderlyingType;
   if (!JsonTypeReflector.FullyTrusted)
     throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Type '{0}' implements ISerializable but cannot be deserialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.\r\nTo fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.\r\n", (IFormatProvider) CultureInfo.InvariantCulture, (object) underlyingType));
   SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, (IFormatterConverter) this.GetFormatterConverter());
   bool flag = false;
   do
   {
     switch (reader.TokenType)
     {
       case JsonToken.PropertyName:
         string name = reader.Value.ToString();
         if (!reader.Read())
           throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected end when setting {0}'s value.", (IFormatProvider) CultureInfo.InvariantCulture, (object) name));
         serializationInfo.AddValue(name, (object) JToken.ReadFrom(reader));
         goto case JsonToken.Comment;
       case JsonToken.Comment:
         continue;
       case JsonToken.EndObject:
         flag = true;
         goto case JsonToken.Comment;
       default:
         throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + (object) reader.TokenType);
     }
   }
   while (!flag && reader.Read());
   if (!flag)
     this.ThrowUnexpectedEndException(reader, (JsonContract) contract, (object) serializationInfo, "Unexpected end when deserializing object.");
   if (contract.ISerializableCreator == null)
     throw JsonSerializationException.Create(reader, StringUtils.FormatWith("ISerializable type '{0}' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present.", (IFormatProvider) CultureInfo.InvariantCulture, (object) underlyingType));
   object o = contract.ISerializableCreator(new object[2]
   {
     (object) serializationInfo,
     (object) this.Serializer.Context
   });
   if (id != null)
     this.AddReference(reader, id, o);
   contract.InvokeOnDeserializing(o, this.Serializer.Context);
   contract.InvokeOnDeserialized(o, this.Serializer.Context);
   return o;
 }
 // Token: 0x06000BD5 RID: 3029
 // RVA: 0x00045544 File Offset: 0x00043744
 private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, string id)
 {
     Type underlyingType = contract.UnderlyingType;
     if (!JsonTypeReflector.FullyTrusted)
     {
         string text = "Type '{0}' implements ISerializable but cannot be deserialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data." + Environment.NewLine + "To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true." + Environment.NewLine;
         text = StringUtils.FormatWith(text, CultureInfo.InvariantCulture, underlyingType);
         throw JsonSerializationException.Create(reader, text);
     }
     if (this.TraceWriter != null && this.TraceWriter.LevelFilter >= TraceLevel.Info)
     {
         this.TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, StringUtils.FormatWith("Deserializing {0} using ISerializable constructor.", CultureInfo.InvariantCulture, contract.UnderlyingType)), null);
     }
     SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new JsonFormatterConverter(this, contract, member));
     bool flag = false;
     string text2;
     do
     {
         JsonToken tokenType = reader.TokenType;
         switch (tokenType)
         {
         case JsonToken.PropertyName:
             text2 = reader.Value.ToString();
             if (!reader.Read())
             {
                 goto IL_119;
             }
             serializationInfo.AddValue(text2, JToken.ReadFrom(reader));
             break;
         case JsonToken.Comment:
             break;
         default:
             if (tokenType != JsonToken.EndObject)
             {
                 goto Block_7;
             }
             flag = true;
             break;
         }
         if (flag)
         {
             break;
         }
     }
     while (reader.Read());
     goto IL_131;
     Block_7:
     throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + reader.TokenType);
     IL_119:
     throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected end when setting {0}'s value.", CultureInfo.InvariantCulture, text2));
     IL_131:
     if (!flag)
     {
         this.ThrowUnexpectedEndException(reader, contract, serializationInfo, "Unexpected end when deserializing object.");
     }
     if (contract.ISerializableCreator == null)
     {
         throw JsonSerializationException.Create(reader, StringUtils.FormatWith("ISerializable type '{0}' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present.", CultureInfo.InvariantCulture, underlyingType));
     }
     object obj = contract.ISerializableCreator(new object[]
     {
         serializationInfo,
         this.Serializer._context
     });
     if (id != null)
     {
         this.AddReference(reader, id, obj);
     }
     this.OnDeserializing(reader, contract, obj);
     this.OnDeserialized(reader, contract, obj);
     return obj;
 }
        private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, string id)
        {
            Type objectType = contract.UnderlyingType;

              if (!JsonTypeReflector.FullyTrusted)
              {
            throw JsonSerializationException.Create(reader, @"Type '{0}' implements ISerializable but cannot be deserialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
            To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.
            ".FormatWith(CultureInfo.InvariantCulture, objectType));
              }

              if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Info)
            TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Deserializing {0} using ISerializable constructor.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType)), null);

              SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, GetFormatterConverter());

              bool finished = false;
              do
              {
            switch (reader.TokenType)
            {
              case JsonToken.PropertyName:
            string memberName = reader.Value.ToString();
            if (!reader.Read())
              throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));

            if (reader.TokenType == JsonToken.StartObject)
            {
              // this will read any potential type names embedded in json
              object o = CreateObject(reader, null, null, null, contract, member, null);
              serializationInfo.AddValue(memberName, o);
            }
            else
            {
              serializationInfo.AddValue(memberName, JToken.ReadFrom(reader));
            }
            break;
              case JsonToken.Comment:
            break;
              case JsonToken.EndObject:
            finished = true;
            break;
              default:
            throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + reader.TokenType);
            }
              } while (!finished && reader.Read());

              if (!finished)
            ThrowUnexpectedEndException(reader, contract, serializationInfo, "Unexpected end when deserializing object.");

              if (contract.ISerializableCreator == null)
            throw JsonSerializationException.Create(reader, "ISerializable type '{0}' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present.".FormatWith(CultureInfo.InvariantCulture, objectType));

              object createdObject = contract.ISerializableCreator(serializationInfo, Serializer._context);

              if (id != null)
            AddReference(reader, id, createdObject);

              // these are together because OnDeserializing takes an object but for an ISerializable the object is fully created in the constructor
              OnDeserializing(reader, contract, createdObject);
              OnDeserialized(reader, contract, createdObject);

              return createdObject;
        }