IDataNode ReadNumericalPrimitiveExtensionDataValue(XmlReaderDelegator xmlReader)
 {
     TypeCode type;
     object numericalValue = JsonObjectDataContract.ParseJsonNumber(xmlReader.ReadContentAsString(), out type);
     switch (type)
     {
         case TypeCode.Byte:
             return new DataNode<byte>((byte)numericalValue);
         case TypeCode.SByte:
             return new DataNode<sbyte>((sbyte)numericalValue);
         case TypeCode.Int16:
             return new DataNode<short>((short)numericalValue);
         case TypeCode.Int32:
             return new DataNode<int>((int)numericalValue);
         case TypeCode.Int64:
             return new DataNode<long>((long)numericalValue);
         case TypeCode.UInt16:
             return new DataNode<ushort>((ushort)numericalValue);
         case TypeCode.UInt32:
             return new DataNode<uint>((uint)numericalValue);
         case TypeCode.UInt64:
             return new DataNode<ulong>((ulong)numericalValue);
         case TypeCode.Single:
             return new DataNode<float>((float)numericalValue);
         case TypeCode.Double:
             return new DataNode<double>((double)numericalValue);
         case TypeCode.Decimal:
             return new DataNode<decimal>((decimal)numericalValue);
         default:
             throw Fx.AssertAndThrow("JsonObjectDataContract.ParseJsonNumber shouldn't return a TypeCode that we're not expecting");
     }
 }
 public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     if (context == null)
     {
         return TryReadNullAtTopLevel(jsonReader) ? null : jsonReader.ReadElementContentAsQName();
     }
     else
     {
         return HandleReadValue(jsonReader.ReadElementContentAsQName(), context);
     }
 }
        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 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;
		}
        protected override IDataNode ReadPrimitiveExtensionDataValue(XmlReaderDelegator xmlReader, string dataContractName, string dataContractNamespace)
        {
            IDataNode dataNode;

            switch (extensionDataValueType)
            {
                case null:
                case JsonGlobals.stringString:
                    dataNode = new DataNode<string>(xmlReader.ReadContentAsString());
                    break;
                case JsonGlobals.booleanString:
                    dataNode = new DataNode<bool>(xmlReader.ReadContentAsBoolean());
                    break;
                case JsonGlobals.numberString:
                    dataNode = ReadNumericalPrimitiveExtensionDataValue(xmlReader);
                    break;
                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.JsonUnexpectedAttributeValue, extensionDataValueType)));
            }

            xmlReader.ReadEndElement();
            return dataNode;
        }
 protected override object ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
 {
     return DataContractJsonSerializer.ReadJsonValue(dataContract, reader, this);
 }
 protected override void StartReadExtensionDataValue(XmlReaderDelegator xmlReader)
 {
     this.extensionDataValueType = xmlReader.GetAttribute("type");
 }
Пример #8
0
 public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     jsonReader.Read();
     object o = null;
     if (context.IsGetOnlyCollection)
     {
         // IsGetOnlyCollection value has already been used to create current collectiondatacontract, value can now be reset. 
         context.IsGetOnlyCollection = false;
         JsonFormatGetOnlyReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, JsonGlobals.itemDictionaryString, TraditionalCollectionDataContract);
     }
     else
     {
         o = JsonFormatReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, JsonGlobals.itemDictionaryString, TraditionalCollectionDataContract);
     }
     jsonReader.ReadEndElement();
     return o;
 }
Пример #9
0
 protected override bool IsReadingClassExtensionData(XmlReaderDelegator xmlReader)
 {
     return(xmlReader.GetAttribute(JsonGlobals.typeString) == JsonGlobals.objectString);
 }
 protected override bool IsReadingClassExtensionData(XmlReaderDelegator xmlReader)
 {
     return xmlReader.GetAttribute(JsonGlobals.typeString) == JsonGlobals.objectString;
 }
 public static string GetJsonMemberName(XmlReaderDelegator xmlReader)
 {
     string name;
     if (!TryGetJsonLocalName(xmlReader, out name))
     {
         name = xmlReader.LocalName;
     }
     return name;
 }
 public int GetJsonMemberIndex(XmlReaderDelegator xmlReader, XmlDictionaryString[] memberNames, int memberIndex, ExtensionDataObject extensionData)
 {
     int length = memberNames.Length;
     if (length != 0)
     {
         for (int i = 0, index = (memberIndex + 1) % length; i < length; i++, index = (index + 1) % length)
         {
             if (xmlReader.IsStartElement(memberNames[index], XmlDictionaryString.Empty))
             {
                 return index;
             }
         }
         string name;
         if (TryGetJsonLocalName(xmlReader, out name))
         {
             for (int i = 0, index = (memberIndex + 1) % length; i < length; i++, index = (index + 1) % length)
             {
                 if (memberNames[index].Value == name)
                 {
                     return index;
                 }
             }
         }
     }
     HandleMemberNotFound(xmlReader, extensionData, memberIndex);
     return length;
 }
Пример #13
0
 public object ReflectionReadClass(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContextComplexJson context, XmlDictionaryString emptyDictionaryString, XmlDictionaryString[] memberNames)
 {
     Debug.Assert(_classContract != null);
     return(_reflectionReader.ReflectionReadClass(xmlReader, context, memberNames, null /*memberNamespaces*/, _classContract));
 }
Пример #14
0
        private void ReadSimpleDictionary(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract, Type keyValueType, object dictionary)
        {
            Type[] keyValueTypes = keyValueType.GetGenericArguments();
            Type   keyType       = keyValueTypes[0];
            Type   valueType     = keyValueTypes[1];

            int  keyTypeNullableDepth = 0;
            Type keyTypeOriginal      = keyType;

            while (keyType.IsGenericType && keyType.GetGenericTypeDefinition() == Globals.TypeOfNullable)
            {
                keyTypeNullableDepth++;
                keyType = keyType.GetGenericArguments()[0];
            }

            ClassDataContract keyValueDataContract = (ClassDataContract)collectionContract.ItemContract;
            DataContract      keyDataContract      = keyValueDataContract.Members[0].MemberTypeContract;

            KeyParseMode keyParseMode = KeyParseMode.Fail;

            if (keyType == Globals.TypeOfString || keyType == Globals.TypeOfObject)
            {
                keyParseMode = KeyParseMode.AsString;
            }
            else if (keyType.IsEnum)
            {
                keyParseMode = KeyParseMode.UsingParseEnum;
            }
            else if (keyDataContract.ParseMethod != null)
            {
                keyParseMode = KeyParseMode.UsingCustomParse;
            }

            if (keyParseMode == KeyParseMode.Fail)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(
                              SR.Format(SR.KeyTypeCannotBeParsedInSimpleDictionary,
                                        DataContract.GetClrTypeFullName(collectionContract.UnderlyingType),
                                        DataContract.GetClrTypeFullName(keyType))
                              ));
            }

            while (true)
            {
                XmlNodeType nodeType = xmlReader.MoveToContent();
                if (nodeType == XmlNodeType.EndElement)
                {
                    return;
                }
                if (nodeType != XmlNodeType.Element)
                {
                    throw XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
                }

                context.IncrementItemCount(1);
                string keyString = XmlObjectSerializerReadContextComplexJson.GetJsonMemberName(xmlReader);
                object pairKey;

                if (keyParseMode == KeyParseMode.UsingParseEnum)
                {
                    pairKey = Enum.Parse(keyType, keyString);
                }
                else if (keyParseMode == KeyParseMode.UsingCustomParse)
                {
                    pairKey = keyDataContract.ParseMethod.Invoke(null, new object[] { keyString });
                }
                else
                {
                    pairKey = keyString;
                }

                if (keyTypeNullableDepth > 0)
                {
                    throw new NotImplementedException("keyTypeNullableDepth > 0");
                }

                object pairValue = ReflectionReadValue(xmlReader, context, valueType, string.Empty, string.Empty);


                ((IDictionary)dictionary).Add(pairKey, pairValue);
            }
        }
Пример #15
0
 public virtual object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     return(TraditionalDataContract.ReadXmlValue(jsonReader, context));
 }
Пример #16
0
 internal static object ReadJsonValue(DataContract contract, XmlReaderDelegator reader, XmlObjectSerializerReadContextComplexJson context)
 {
     return(JsonDataContract.GetJsonDataContract(contract).ReadJsonValue(reader, context));
 }
 protected override void StartReadExtensionDataValue(XmlReaderDelegator xmlReader)
 {
     _extensionDataValueType = xmlReader.GetAttribute(JsonGlobals.typeString);
 }
 protected override object ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
 {
     return(DataContractJsonSerializerImpl.ReadJsonValue(dataContract, reader, this));
 }
 public override void ReadAttributes(XmlReaderDelegator xmlReader)
        internal override void ReadAttributes(XmlReaderDelegator xmlReader)
#endif
        {
            if (attributes == null)
                attributes = new Attributes();
            attributes.Reset();

            if (xmlReader.MoveToAttribute(JsonGlobals.typeString) && xmlReader.Value == JsonGlobals.nullString)
            {
                attributes.XsiNil = true;
            }
            else if (xmlReader.MoveToAttribute(JsonGlobals.serverTypeString))
            {
                XmlQualifiedName qualifiedTypeName = JsonReaderDelegator.ParseQualifiedName(xmlReader.Value);
                attributes.XsiTypeName = qualifiedTypeName.Name;

                string serverTypeNamespace = qualifiedTypeName.Namespace;

                if (!string.IsNullOrEmpty(serverTypeNamespace))
                {
                    switch (serverTypeNamespace[0])
                    {
                        case '#':
                            serverTypeNamespace = string.Concat(Globals.DataContractXsdBaseNamespace, serverTypeNamespace.Substring(1));
                            break;
                        case '\\':
                            if (serverTypeNamespace.Length >= 2)
                            {
                                switch (serverTypeNamespace[1])
                                {
                                    case '#':
                                    case '\\':
                                        serverTypeNamespace = serverTypeNamespace.Substring(1);
                                        break;
                                    default:
                                        break;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }

                attributes.XsiTypeNamespace = serverTypeNamespace;
            }
            xmlReader.MoveToElement();
        }
Пример #21
0
 public void ReflectionReadGetOnlyCollection(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContextComplexJson context, XmlDictionaryString emptyDictionaryString, XmlDictionaryString itemName, CollectionDataContract collectionContract)
 {
     _reflectionReader.ReflectionReadGetOnlyCollection(xmlReader, context, itemName, emptyDictionaryString /*itemNamespace*/, collectionContract);
 }
 internal static bool TryGetJsonLocalName(XmlReaderDelegator xmlReader, out string name)
 {
     if (xmlReader.IsStartElement(JsonGlobals.itemDictionaryString, JsonGlobals.itemDictionaryString))
     {
         if (xmlReader.MoveToAttribute(JsonGlobals.itemString))
         {
             name = xmlReader.Value;
             return true;
         }
     }
     name = null;
     return false;
 }
Пример #23
0
 public override void ReadAttributes(XmlReaderDelegator xmlReader)
 protected override bool IsReadingCollectionExtensionData(XmlReaderDelegator xmlReader)
 {
     return xmlReader.GetAttribute(JsonGlobals.typeString) == JsonGlobals.arrayString;
 }
 protected override bool IsReadingCollectionExtensionData(XmlReaderDelegator xmlReader)
 {
     return(xmlReader.GetAttribute("type") == "array");
 }
 protected override void StartReadExtensionDataValue(XmlReaderDelegator xmlReader)
 {
     extensionDataValueType = xmlReader.GetAttribute(JsonGlobals.typeString);
 }
Пример #27
0
 protected override bool IsReadingCollectionExtensionData(XmlReaderDelegator xmlReader)
 {
     return(xmlReader.GetAttribute(JsonGlobals.typeString) == JsonGlobals.arrayString);
 }
		public object ReadCollectionFromJson (XmlReaderDelegator xmlReader, XmlObjectSerializerReadContextComplexJson context, XmlDictionaryString emptyDictionaryString, XmlDictionaryString itemName, CollectionDataContract collectionContract)
		{
			#region GenerateCollectionReaderHelper
			// InitArgs()
			this.xmlReader = xmlReader;
			this.context = context;
			this.emptyDictionaryString = emptyDictionaryString;
			this.itemName = itemName;

			this.collectionContract = collectionContract;

			#endregion

			ReadCollection (collectionContract);

			return objectLocal;
		}
Пример #29
0
 public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     jsonReader.Read();
     object o = JsonFormatReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, MemberNames);
     jsonReader.ReadEndElement();
     return o;
 }
 protected override bool IsReadingClassExtensionData(XmlReaderDelegator xmlReader)
 {
     return(xmlReader.GetAttribute("type") == "object");
 }
Пример #31
-1
        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;
        }