ReadJsonValue() статический приватный Метод

static private ReadJsonValue ( System.Runtime.Serialization.DataContract contract, System.Runtime.Serialization.XmlReaderDelegator reader, System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson context ) : object
contract System.Runtime.Serialization.DataContract
reader System.Runtime.Serialization.XmlReaderDelegator
context System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson
Результат object
        internal override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
        {
            if (MaxItemsInObjectGraph == 0)
            {
                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph));
            }

            if (verifyObjectName)
            {
                if (!InternalIsStartObject(xmlReader))
                {
                    throw XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElement, XmlDictionaryString.Empty, RootName), xmlReader);
                }
            }
            else if (!IsStartElement(xmlReader))
            {
                throw XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElementAtDeserialize, XmlNodeType.Element), xmlReader);
            }

            DataContract contract = RootContract;

            if (contract.IsPrimitive && object.ReferenceEquals(contract.UnderlyingType, _rootType))// handle Nullable<T> differently
            {
                return(DataContractJsonSerializerImpl.ReadJsonValue(contract, xmlReader, null));
            }

            XmlObjectSerializerReadContextComplexJson context = XmlObjectSerializerReadContextComplexJson.CreateContext(this, contract);

            return(context.InternalDeserialize(xmlReader, _rootType, contract, null, null));
        }
Пример #2
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(DataContractJsonSerializerImpl.ReadJsonValue(DataContract.GetDataContract(Globals.TypeOfObjectArray), jsonReader, context));

            default:
                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.JsonUnexpectedAttributeValue, contentMode));
            }

            if (context != null)
            {
                context.AddNewObject(obj);
            }
            return(obj);
        }
 protected override object ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
 {
     return(DataContractJsonSerializerImpl.ReadJsonValue(dataContract, reader, this));
 }