Beispiel #1
0
        public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
        {
            object obj;
            string contentMode = jsonReader.GetAttribute(JsonGlobals.typeString);

            switch (contentMode)
            {
            case JsonGlobals.nullString:
                jsonReader.Skip();
                obj = null;
                break;

            case JsonGlobals.booleanString:
                obj = jsonReader.ReadElementContentAsBoolean();
                break;

            case JsonGlobals.stringString:
            case null:
                obj = jsonReader.ReadElementContentAsString();
                break;

            case JsonGlobals.numberString:
                obj = ParseJsonNumber(jsonReader.ReadElementContentAsString());
                break;

            case JsonGlobals.objectString:
                jsonReader.Skip();
                obj = new object();
                break;

            case JsonGlobals.arrayString:
                // Read as object array
                return(DataContractJsonSerializer.ReadJsonValue(DataContract.GetDataContract(Globals.TypeOfObjectArray), jsonReader, context));

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.JsonUnexpectedAttributeValue, contentMode)));
            }

            if (context != null)
            {
                context.AddNewObject(obj);
            }
            return(obj);
        }
Beispiel #2
0
 protected static bool TryReadNullAtTopLevel(XmlReaderDelegator reader)
 {
     while (reader.MoveToAttribute("type") && (reader.Value == "null"))
     {
         reader.Skip();
         reader.MoveToElement();
         return(true);
     }
     reader.MoveToElement();
     return(false);
 }
Beispiel #3
0
        protected static bool TryReadNullAtTopLevel(XmlReaderDelegator reader)
        {
            if (reader.MoveToAttribute(JsonGlobals.typeString) && (reader.Value == JsonGlobals.nullString))
            {
                reader.Skip();
                reader.MoveToElement();
                return(true);
            }

            reader.MoveToElement();
            return(false);
        }