public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { string xmlContent = jsonReader.ReadElementContentAsString(); DataContractSerializer dataContractSerializer = new DataContractSerializer(TraditionalDataContract.UnderlyingType, GetKnownTypesFromContext(context, (context == null) ? null : context.SerializerKnownTypeList), 1, false, false); // maxItemsInObjectGraph // ignoreExtensionDataObject // preserveObjectReferences MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xmlContent)); object xmlValue; XmlDictionaryReaderQuotas quotas = ((JsonReaderDelegator)jsonReader).ReaderQuotas; if (quotas == null) { xmlValue = dataContractSerializer.ReadObject(memoryStream); } else { xmlValue = dataContractSerializer.ReadObject(XmlDictionaryReader.CreateTextReader(memoryStream, quotas)); } if (context != null) { context.AddNewObject(xmlValue); } return(xmlValue); }
public override object?ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson?context) { object enumValue; if (IsULong) { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsUnsignedLong()); } else { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsLong()); } context?.AddNewObject(enumValue); return(enumValue); }
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); }
public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { object enumValue; if (IsULong) { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsUnsignedLong()); } else { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsLong()); } if (context != null) { context.AddNewObject(enumValue); } return enumValue; }
public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { object obj2; if (this.IsULong) { obj2 = Enum.ToObject(base.TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsUnsignedLong()); } else { obj2 = Enum.ToObject(base.TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsLong()); } if (context != null) { context.AddNewObject(obj2); } return(obj2); }
public object ReadFromJson(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContextComplexJson context, XmlDictionaryString emptyDictionaryString, XmlDictionaryString[] memberNames) { // InitArgs() this.xmlReader = xmlReader; this.context = context; this.emptyDictionaryString = emptyDictionaryString; this.memberNames = memberNames; //DemandSerializationFormatterPermission(classContract); //DemandMemberAccessPermission(memberAccessFlag); CreateObject(classContract); context.AddNewObject(objectLocal); InvokeOnDeserializing(classContract); string objectId = null; if (classContract.IsISerializable) { ReadISerializable(classContract); } else { ReadClass(classContract); } if (Globals.TypeOfIDeserializationCallback.IsAssignableFrom(classContract.UnderlyingType)) { ((IDeserializationCallback)objectLocal).OnDeserialization(null); } InvokeOnDeserialized(classContract); if (!InvokeFactoryMethod(classContract)) { // Do a conversion back from DateTimeOffsetAdapter to DateTimeOffset after deserialization. // DateTimeOffsetAdapter is used here for deserialization purposes to bypass the ISerializable implementation // on DateTimeOffset; which does not work in partial trust. if (classContract.UnderlyingType == Globals.TypeOfDateTimeOffsetAdapter) { objectLocal = DateTimeOffsetAdapter.GetDateTimeOffset((DateTimeOffsetAdapter)objectLocal); } // else - do we have to call CodeInterpreter.ConvertValue()? I guess not... } return(objectLocal); }
public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { object obj2; string s = jsonReader.ReadElementContentAsString(); DataContractSerializer serializer = new DataContractSerializer(base.TraditionalDataContract.UnderlyingType, this.GetKnownTypesFromContext(context, (context == null) ? null : context.SerializerKnownTypeList), 1, false, false, null); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(s)); XmlDictionaryReaderQuotas readerQuotas = ((JsonReaderDelegator) jsonReader).ReaderQuotas; if (readerQuotas == null) { obj2 = serializer.ReadObject(stream); } else { obj2 = serializer.ReadObject(XmlDictionaryReader.CreateTextReader(stream, readerQuotas)); } if (context != null) { context.AddNewObject(obj2); } return obj2; }
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; }
public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { object obj2; string s = jsonReader.ReadElementContentAsString(); DataContractSerializer serializer = new DataContractSerializer(base.TraditionalDataContract.UnderlyingType, this.GetKnownTypesFromContext(context, (context == null) ? null : context.SerializerKnownTypeList), 1, false, false, null); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(s)); XmlDictionaryReaderQuotas readerQuotas = ((JsonReaderDelegator)jsonReader).ReaderQuotas; if (readerQuotas == null) { obj2 = serializer.ReadObject(stream); } else { obj2 = serializer.ReadObject(XmlDictionaryReader.CreateTextReader(stream, readerQuotas)); } if (context != null) { context.AddNewObject(obj2); } return(obj2); }
public object ReadFromJson (XmlReaderDelegator xmlReader, XmlObjectSerializerReadContextComplexJson context, XmlDictionaryString emptyDictionaryString, XmlDictionaryString[] memberNames) { // InitArgs() this.xmlReader = xmlReader; this.context = context; this.emptyDictionaryString = emptyDictionaryString; this.memberNames = memberNames; //DemandSerializationFormatterPermission(classContract); //DemandMemberAccessPermission(memberAccessFlag); CreateObject (classContract); context.AddNewObject (objectLocal); InvokeOnDeserializing (classContract); string objectId = null; if (classContract.IsISerializable) ReadISerializable (classContract); else ReadClass (classContract); if (Globals.TypeOfIDeserializationCallback.IsAssignableFrom (classContract.UnderlyingType)) ((IDeserializationCallback) objectLocal).OnDeserialization (null); InvokeOnDeserialized(classContract); if (!InvokeFactoryMethod (classContract)) { // Do a conversion back from DateTimeOffsetAdapter to DateTimeOffset after deserialization. // DateTimeOffsetAdapter is used here for deserialization purposes to bypass the ISerializable implementation // on DateTimeOffset; which does not work in partial trust. if (classContract.UnderlyingType == Globals.TypeOfDateTimeOffsetAdapter) objectLocal = DateTimeOffsetAdapter.GetDateTimeOffset ((DateTimeOffsetAdapter) objectLocal); // else - do we have to call CodeInterpreter.ConvertValue()? I guess not... } return objectLocal; }
object ReadValue(Type type, string name) { var valueType = type; object value = null; bool shouldAssignNullableValue = false; int nullables = 0; while (type.IsGenericType && type.GetGenericTypeDefinition() == Globals.TypeOfNullable) { nullables++; type = type.GetGenericArguments() [0]; } PrimitiveDataContract primitiveContract = PrimitiveDataContract.GetPrimitiveDataContract(type); if ((primitiveContract != null && primitiveContract.UnderlyingType != Globals.TypeOfObject) || nullables != 0 || type.IsValueType) { context.ReadAttributes(xmlReader); string objectId = context.ReadIfNullOrRef(xmlReader, type, DataContract.IsTypeSerializable(type)); // Deserialize null if (objectId == Globals.NullObjectId) { if (nullables != 0) { value = Activator.CreateInstance(valueType); } else if (type.IsValueType) { throw new SerializationException(SR.GetString(SR.ValueTypeCannotBeNull, DataContract.GetClrTypeFullName(type))); } else { value = null; } } else if (objectId == string.Empty) { // Deserialize value // Compare against Globals.NewObjectId, which is set to string.Empty objectId = context.GetObjectId(); if (type.IsValueType) { if (!string.IsNullOrEmpty(objectId)) { throw new SerializationException(SR.GetString(SR.ValueTypeCannotHaveId, DataContract.GetClrTypeFullName(type))); } } object innerValueRead = null; if (nullables != 0) { shouldAssignNullableValue = true; } if (primitiveContract != null && primitiveContract.UnderlyingType != Globals.TypeOfObject) { value = primitiveContract.XmlFormatReaderMethod.Invoke(xmlReader, new object [0]); if (!type.IsValueType) { context.AddNewObject(value); } } else { value = InternalDeserialize(type, name); } } else { // Deserialize ref if (type.IsValueType) { throw new SerializationException(SR.GetString(SR.ValueTypeCannotHaveRef, DataContract.GetClrTypeFullName(type))); } else { value = CodeInterpreter.ConvertValue(context.GetExistingObject(objectId, type, name, string.Empty), Globals.TypeOfObject, type); } } if (shouldAssignNullableValue) { if (objectId != Globals.NullObjectId) { value = WrapNullableObject(type, value, valueType, nullables); } } } else { value = InternalDeserialize(type, name); } return(value); }
public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { object obj2; string attribute = jsonReader.GetAttribute("type"); string key = attribute; if (key != null) { int num; if (<PrivateImplementationDetails>{D290E7C2-4296-4D66-A436-0C17851A078B}.$$method0x60012be-1.TryGetValue(key, out num)) { switch (num) { case 0: jsonReader.Skip(); obj2 = null; goto Label_011B; case 1: obj2 = jsonReader.ReadElementContentAsBoolean(); goto Label_011B; case 2: goto Label_00BB; case 3: obj2 = ParseJsonNumber(jsonReader.ReadElementContentAsString()); goto Label_011B; case 4: jsonReader.Skip(); obj2 = new object(); goto Label_011B; case 5: return DataContractJsonSerializer.ReadJsonValue(DataContract.GetDataContract(Globals.TypeOfObjectArray), jsonReader, context); } } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("JsonUnexpectedAttributeValue", new object[] { attribute }))); } Label_00BB: obj2 = jsonReader.ReadElementContentAsString(); Label_011B: if (context != null) { context.AddNewObject(obj2); } return obj2; }
public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { string xmlContent = jsonReader.ReadElementContentAsString(); DataContractSerializer dataContractSerializer = new DataContractSerializer(TraditionalDataContract.UnderlyingType, GetKnownTypesFromContext(context, (context == null) ? null : context.SerializerKnownTypeList), 1, false, false); // maxItemsInObjectGraph // ignoreExtensionDataObject // preserveObjectReferences MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xmlContent)); object xmlValue; XmlDictionaryReaderQuotas quotas = ((JsonReaderDelegator)jsonReader).ReaderQuotas; if (quotas == null) { xmlValue = dataContractSerializer.ReadObject(memoryStream); } else { xmlValue = dataContractSerializer.ReadObject(XmlDictionaryReader.CreateTextReader(memoryStream, quotas)); } if (context != null) { context.AddNewObject(xmlValue); } return xmlValue; }