예제 #1
0
 private void ReflectionReadMembers(object obj, XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces)
 {
     int memberCount = _classContract.MemberNames.Length;
     context.IncrementItemCount(memberCount);
     int memberIndex = -1;
     int firstRequiredMember;
     bool[] requiredMembers = GetRequiredMembers(_classContract, out firstRequiredMember);
     bool hasRequiredMembers = (firstRequiredMember < memberCount);
     int requiredIndex = hasRequiredMembers ? firstRequiredMember : -1;
     int index = -1;
     while (true)
     {
         if (!XmlObjectSerializerReadContext.MoveToNextElement(xmlReader))
         {
             return;
         }
         if (hasRequiredMembers)
         {
             index = context.GetMemberIndexWithRequiredMembers(xmlReader, memberNames, memberNamespaces, memberIndex, requiredIndex, null);
         }
         else
         {
             index = context.GetMemberIndex(xmlReader, memberNames, memberNamespaces, memberIndex, null);
         }
         ReflectionReadMember(obj, index, xmlReader, context, memberNames, memberNamespaces);
         memberIndex = index;
         requiredIndex = index + 1;
     }
 }
 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;
 }
 public object ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     this.PushKnownDataContracts(context);
     object obj2 = this.ReadJsonValueCore(jsonReader, context);
     this.PopKnownDataContracts(context);
     return obj2;
 }
예제 #4
0
 private void ReflectionInitArgs(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces)
 {
     _arg0XmlReader = xmlReader;
     _arg1Context = context;
     _arg2MemberNames = memberNames;
     _arg3MemberNamespaces = memberNamespaces;
 }
예제 #5
0
 public object ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     PushKnownDataContracts(context);
     object deserializedObject = ReadJsonValueCore(jsonReader, context);
     PopKnownDataContracts(context);
     return deserializedObject;
 }
 public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     jsonReader.Read();
     object obj2 = this.JsonFormatReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, this.MemberNames);
     jsonReader.ReadEndElement();
     return obj2;
 }
 public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
 {
     xmlReader.Read();
     Type underlyingType = base.UnderlyingType;
     object obj2 = underlyingType.IsArray ? Array.CreateInstance(underlyingType.GetElementType(), 0) : this.GetUninitializedObject(underlyingType);
     context.AddNewObject(obj2);
     string objectId = context.GetObjectId();
     SerializationInfo serInfo = context.ReadSerializationInfo(xmlReader, underlyingType);
     object newObj = this.SerializationSurrogateSetObjectData(obj2, serInfo, context.GetStreamingContext());
     if (newObj == null)
     {
         newObj = obj2;
     }
     if (newObj is IDeserializationCallback)
     {
         ((IDeserializationCallback) newObj).OnDeserialization(null);
     }
     if (newObj is IObjectReference)
     {
         newObj = GetRealObject((IObjectReference) newObj, context.GetStreamingContext());
     }
     context.ReplaceDeserializedObject(objectId, obj2, newObj);
     xmlReader.ReadEndElement();
     return newObj;
 }
 public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context)
 {
     object obj2;
     if (reader.IsEmptyElement)
     {
         reader.Skip();
         obj2 = new object();
     }
     else
     {
         string localName = reader.LocalName;
         string namespaceURI = reader.NamespaceURI;
         reader.Read();
         try
         {
             reader.ReadEndElement();
             obj2 = new object();
         }
         catch (XmlException exception)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("XmlForObjectCannotHaveContent", new object[] { localName, namespaceURI }), exception));
         }
     }
     if (context != null)
     {
         return base.HandleReadValue(obj2, context);
     }
     return obj2;
 }
 public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context)
 {
     if (context != null)
     {
         return base.HandleReadValue(reader.ReadElementContentAsChar(), context);
     }
     return reader.ReadElementContentAsChar();
 }
 internal void Read(XmlReaderDelegator reader)
 {
     this.Reset();
     while (reader.MoveToNextAttribute())
     {
         switch (reader.IndexOfLocalName(serializationLocalNames, DictionaryGlobals.SerializationNamespace))
         {
             case 0:
             {
                 this.ReadId(reader);
                 continue;
             }
             case 1:
             {
                 this.ReadArraySize(reader);
                 continue;
             }
             case 2:
             {
                 this.ReadRef(reader);
                 continue;
             }
             case 3:
             {
                 this.ClrType = reader.Value;
                 continue;
             }
             case 4:
             {
                 this.ClrAssembly = reader.Value;
                 continue;
             }
             case 5:
             {
                 this.ReadFactoryType(reader);
                 continue;
             }
         }
         switch (reader.IndexOfLocalName(schemaInstanceLocalNames, DictionaryGlobals.SchemaInstanceNamespace))
         {
             case 0:
             {
                 this.ReadXsiNil(reader);
                 continue;
             }
             case 1:
             {
                 this.ReadXsiType(reader);
                 continue;
             }
         }
         if (!reader.IsNamespaceUri(DictionaryGlobals.XmlnsNamespace))
         {
             this.UnrecognizedAttributesFound = true;
         }
     }
     reader.MoveToElement();
 }
예제 #11
0
 internal void BeginRead(XmlReaderDelegator xmlReader)
 {
     if (xmlReader.NodeType != XmlNodeType.Element)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
     _xmlReader = xmlReader;
     _startDepth = xmlReader.Depth;
     _innerReader = xmlReader.UnderlyingReader;
     _isRootEmptyElement = InnerReader.IsEmptyElement;
 }
 protected static bool TryReadNullAtTopLevel(XmlReaderDelegator reader)
 {
     while (reader.MoveToAttribute("type") && (reader.Value == "null"))
     {
         reader.Skip();
         reader.MoveToElement();
         return true;
     }
     reader.MoveToElement();
     return false;
 }
 public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
 {
     if (context != null)
     {
         return JsonDataContract.HandleReadValue(jsonReader.ReadElementContentAsBase64(), context);
     }
     if (!JsonDataContract.TryReadNullAtTopLevel(jsonReader))
     {
         return jsonReader.ReadElementContentAsBase64();
     }
     return null;
 }
 public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context)
 {
     if (context != null)
     {
         return base.HandleReadValue(reader.ReadElementContentAsQName(), context);
     }
     if (!base.TryReadNullAtTopLevel(reader))
     {
         return reader.ReadElementContentAsQName();
     }
     return null;
 }
 internal override object InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, string name, string ns)
 {
     if (_mode == SerializationMode.SharedContract)
     {
         if (_serializationSurrogateProvider == null)
             return base.InternalDeserialize(xmlReader, declaredType, name, ns);
         else
             return InternalDeserializeWithSurrogate(xmlReader, declaredType, null /*surrogateDataContract*/, name, ns);
     }
     else
     {
         return InternalDeserializeInSharedTypeMode(xmlReader, -1, declaredType, name, ns);
     }
 }
 internal override object InternalDeserialize(XmlReaderDelegator xmlReader, int declaredTypeID, RuntimeTypeHandle declaredTypeHandle, string name, string ns)
 {
     if (_mode == SerializationMode.SharedContract)
     {
         //if (dataContractSurrogate == null)
         return base.InternalDeserialize(xmlReader, declaredTypeID, declaredTypeHandle, name, ns);
         //else
         //    return InternalDeserializeWithSurrogate(xmlReader, Type.GetTypeFromHandle(declaredTypeHandle), null /*surrogateDataContract*/, name, ns);
     }
     else
     {
         return InternalDeserializeInSharedTypeMode(xmlReader, declaredTypeID, Type.GetTypeFromHandle(declaredTypeHandle), name, ns);
     }
 }
 internal override object InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, string name, string ns)
 {
     if (_mode == SerializationMode.SharedContract)
     {
         //if (dataContractSurrogate == null)
         return base.InternalDeserialize(xmlReader, declaredType, dataContract, name, ns);
         //else
         //    return InternalDeserializeWithSurrogate(xmlReader, declaredType, dataContract, name, ns);
     }
     else
     {
         return InternalDeserializeInSharedTypeMode(xmlReader, -1, declaredType, name, ns);
     }
 }
 protected bool TryReadNullAtTopLevel(XmlReaderDelegator reader)
 {
     System.Runtime.Serialization.Attributes attributes = new System.Runtime.Serialization.Attributes();
     attributes.Read(reader);
     if (attributes.Ref != Globals.NewObjectId)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("CannotDeserializeRefAtTopLevel", new object[] { attributes.Ref })));
     }
     if (attributes.XsiNil)
     {
         reader.Skip();
         return true;
     }
     return false;
 }
        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)
 {
     jsonReader.Read();
     object obj2 = null;
     if (context.IsGetOnlyCollection)
     {
         context.IsGetOnlyCollection = false;
         this.JsonFormatGetOnlyReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, JsonGlobals.itemDictionaryString, this.TraditionalCollectionDataContract);
     }
     else
     {
         obj2 = this.JsonFormatReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, JsonGlobals.itemDictionaryString, this.TraditionalCollectionDataContract);
     }
     jsonReader.ReadEndElement();
     return obj2;
 }
예제 #21
0
        internal void Read(XmlReaderDelegator reader)
        {
            Reset();

            while (reader.MoveToNextAttribute())
            {
                switch (reader.IndexOfLocalName(s_serializationLocalNames, DictionaryGlobals.SerializationNamespace))
                {
                    case 0:
                        ReadId(reader);
                        break;
                    case 1:
                        ReadArraySize(reader);
                        break;
                    case 2:
                        ReadRef(reader);
                        break;
                    case 3:
                        ClrType = reader.Value;
                        break;
                    case 4:
                        ClrAssembly = reader.Value;
                        break;
                    case 5:
                        ReadFactoryType(reader);
                        break;
                    default:
                        switch (reader.IndexOfLocalName(s_schemaInstanceLocalNames, DictionaryGlobals.SchemaInstanceNamespace))
                        {
                            case 0:
                                ReadXsiNil(reader);
                                break;
                            case 1:
                                ReadXsiType(reader);
                                break;
                            default:
                                if (!reader.IsNamespaceUri(DictionaryGlobals.XmlnsNamespace))
                                    UnrecognizedAttributesFound = true;
                                break;
                        }
                        break;
                }
            }
            reader.MoveToElement();
        }
예제 #22
0
        internal object ReflectionReadClass(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces)
        {
            ReflectionInitArgs(xmlReader, context, memberNames, memberNamespaces);
            object obj = ReflectionCreateObject(_classContract);
            context.AddNewObject(obj);
            ReflectionReadMembers(obj, xmlReader, context, memberNames, memberNamespaces);

            if (obj.GetType() == typeof(DateTimeOffsetAdapter))
            {
                obj = DateTimeOffsetAdapter.GetDateTimeOffset((DateTimeOffsetAdapter)obj);
            }
            else if (obj.GetType().GetTypeInfo().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(KeyValuePairAdapter<,>))
            {
                obj = _classContract.GetKeyValuePairMethodInfo.Invoke(obj, Array.Empty<object>());
            }

            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;
 }
예제 #24
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;
        }
		public object ReadFromXml (XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces)
		{
			// InitArgs()
			this.xmlReader = xmlReader;
			this.context = context;
			this.memberNames = memberNames;
			this.memberNamespaces = memberNamespaces;
			
			//DemandSerializationFormatterPermission(classContract);
			//DemandMemberAccessPermission(memberAccessFlag);
			CreateObject (classContract);
			
			context.AddNewObject (objectLocal);
			InvokeOnDeserializing (classContract);
            
            string objectId = null;
            
			if (HasFactoryMethod (classContract))
				objectId = context.GetObjectId ();
			if (classContract.IsISerializable)
				ReadISerializable (classContract);
			else
				ReadClass (classContract);
			bool isFactoryType = InvokeFactoryMethod (classContract, objectId);
			if (Globals.TypeOfIDeserializationCallback.IsAssignableFrom (classContract.UnderlyingType))
				((IDeserializationCallback) objectLocal).OnDeserialization (null);
			InvokeOnDeserialized(classContract);
			if (objectId == null || !isFactoryType) {

				// 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;
		}
        private object InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, int declaredTypeID, Type declaredType, string name, string ns)
        {
            object retObj = null;
            if (TryHandleNullOrRef(xmlReader, declaredType, name, ns, ref retObj))
                return retObj;

            DataContract dataContract;
            string assemblyName = attributes.ClrAssembly;
            string typeName = attributes.ClrType;
            if (assemblyName != null && typeName != null)
            {
                Assembly assembly;
                Type type;
                dataContract = ResolveDataContractInSharedTypeMode(assemblyName, typeName, out assembly, out type);
                if (dataContract == null)
                {
                    if (assembly == null)
                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.AssemblyNotFound, assemblyName));
                    if (type == null)
                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ClrTypeNotFound, assembly.FullName, typeName));
                }
                //Array covariance is not supported in XSD. If declared type is array, data is sent in format of base array
                if (declaredType != null && declaredType.IsArray)
                    dataContract = (declaredTypeID < 0) ? GetDataContract(declaredType) : GetDataContract(declaredTypeID, declaredType.TypeHandle);
            }
            else
            {
                if (assemblyName != null)
                    throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.AttributeNotFound, Globals.SerializationNamespace, Globals.ClrTypeLocalName, xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName)));
                else if (typeName != null)
                    throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.AttributeNotFound, Globals.SerializationNamespace, Globals.ClrAssemblyLocalName, xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName)));
                else if (declaredType == null)
                    throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.AttributeNotFound, Globals.SerializationNamespace, Globals.ClrTypeLocalName, xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName)));
                dataContract = (declaredTypeID < 0) ? GetDataContract(declaredType) : GetDataContract(declaredTypeID, declaredType.TypeHandle);
            }
            return ReadDataContractValue(dataContract, xmlReader);
        }
예제 #27
0
        protected override void ReflectionReadMembers(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces, ClassDataContract classContract, ref object obj)
        {
            int memberCount = classContract.MemberNames.Length;
            context.IncrementItemCount(memberCount);
            int memberIndex = -1;
            int firstRequiredMember;
            bool[] requiredMembers = GetRequiredMembers(classContract, out firstRequiredMember);
            bool hasRequiredMembers = (firstRequiredMember < memberCount);
            int requiredIndex = hasRequiredMembers ? firstRequiredMember : -1;
            DataMember[] members = new DataMember[memberCount];
            int reflectedMemberCount = ReflectionGetMembers(classContract, members);
            Debug.Assert(reflectedMemberCount == memberCount, "The value returned by ReflectionGetMembers() should equal to memberCount.");

            while (true)
            {
                if (!XmlObjectSerializerReadContext.MoveToNextElement(xmlReader))
                {
                    return;
                }
                if (hasRequiredMembers)
                {
                    memberIndex = context.GetMemberIndexWithRequiredMembers(xmlReader, memberNames, memberNamespaces, memberIndex, requiredIndex, null);
                }
                else
                {
                    memberIndex = context.GetMemberIndex(xmlReader, memberNames, memberNamespaces, memberIndex, null);
                }

                // GetMemberIndex returns memberNames.Length if member not found
                if (memberIndex < members.Length)
                {
                    ReflectionReadMember(xmlReader, context, classContract, ref obj, memberIndex, members);
                    requiredIndex = memberIndex + 1;
                }
            }
        }
예제 #28
0
 public static Exception CreateUnexpectedStateException(XmlNodeType expectedState, XmlReaderDelegator xmlReader)
예제 #29
0
 public int GetMemberIndexWithRequiredMembers(XmlReaderDelegator xmlReader, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces, int memberIndex, int requiredIndex, ExtensionDataObject extensionData)
예제 #30
0
 public static void ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, int memberIndex, int requiredIndex, XmlDictionaryString[] memberNames)
예제 #31
0
 protected virtual bool IsReadingCollectionExtensionData(XmlReaderDelegator xmlReader)
 {
     return(attributes.ArraySZSize != -1);
 }
예제 #32
0
 public virtual object InternalDeserialize(XmlReaderDelegator xmlReader, int id, RuntimeTypeHandle declaredTypeHandle, string name, string ns)
예제 #33
0
 public static bool MoveToNextElement(XmlReaderDelegator xmlReader)
예제 #34
0
 internal static object ReadRootIXmlSerializable(XmlReaderDelegator xmlReader, XmlDataContract xmlDataContract, bool isMemberType)
 {
     return(ReadIXmlSerializable(new XmlSerializableReader(), xmlReader, xmlDataContract, isMemberType));
 }
예제 #35
0
 internal static Exception CreateSerializationExceptionWithReaderDetails(string errorMessage, XmlReaderDelegator reader)
 {
     return(XmlObjectSerializer.CreateSerializationException(TryAddLineInfo(reader, SR.Format(SR.EncounteredWithNameNamespace, errorMessage, reader.NodeType, reader.LocalName, reader.NamespaceURI))));
 }
예제 #36
0
 internal bool IsStartElement(XmlReaderDelegator reader)
 {
     return(reader.MoveToElement() || reader.IsStartElement());
 }
예제 #37
0
 internal object ReadObjectHandleExceptions(XmlReaderDelegator reader, bool verifyObjectName)
 {
     return(ReadObjectHandleExceptions(reader, verifyObjectName, null));
 }
예제 #38
0
 internal virtual bool InternalIsStartObject(XmlReaderDelegator reader)
 {
     DiagnosticUtility.DebugAssert("XmlObjectSerializer.InternalIsStartObject should never get called");
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 }
예제 #39
0
 public string ReadIfNullOrRef(XmlReaderDelegator xmlReader, Type memberType, bool isMemberTypeSerializable)
예제 #40
0
 public virtual void ReadAttributes(XmlReaderDelegator xmlReader)
예제 #41
0
        public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
        {
            XmlReaderDelegator xmlDelegator = ParseReaderString(xmlReader);

            ClassDataContract cdc = new ClassDataContract(this.UnderlyingType);

            // The Class Data Contract created from the underlying exception type uses custom imported members that are 
            // created in this classes constructor. Here we clear out the Class Data Contract's default members and insert our own.
            cdc.Members.Clear();
            foreach (DataMember dm in this.Members)
            {
                cdc.Members.Add(dm);
            }

            cdc.MemberNames = _memberNames;
            cdc.ContractNamespaces = _contractNamespaces;
            cdc.MemberNamespaces = _memberNamespaces;

            object obj = cdc.ReadXmlValue(xmlDelegator, context);

            if (context != null)
                context.AddNewObject(obj);
            return obj;
        }
예제 #42
0
        internal static object ReadIXmlSerializable(XmlSerializableReader xmlSerializableReader, XmlReaderDelegator xmlReader, XmlDataContract xmlDataContract, bool isMemberType)
        {
            object obj = null;

            xmlSerializableReader.BeginRead(xmlReader);
            if (isMemberType && !xmlDataContract.HasRoot)
            {
                xmlReader.Read();
                xmlReader.MoveToContent();
            }
            {
                IXmlSerializable xmlSerializable = xmlDataContract.CreateXmlSerializableDelegate();
                xmlSerializable.ReadXml(xmlSerializableReader);
                obj = xmlSerializable;
            }
            xmlSerializableReader.EndRead();
            return(obj);
        }
예제 #43
0
 internal override bool InternalIsStartObject(XmlReaderDelegator reader)
 {
     return(IsRootElement(reader, RootContract, _rootName, _rootNamespace));
 }
예제 #44
0
        internal static Exception CreateUnexpectedStateException(XmlNodeType expectedState, XmlReaderDelegator xmlReader)
#endif
        {
            return(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingState, expectedState), xmlReader));
        }
예제 #45
0
        internal static bool MoveToNextElement(XmlReaderDelegator xmlReader)
#endif
        {
            return(xmlReader.MoveToContent() != XmlNodeType.EndElement);
        }
예제 #46
0
        internal object ReadEnumValue(XmlReaderDelegator reader)
        {
            string stringValue = reader.ReadElementContentAsString();
            long   longValue   = 0;
            int    i           = 0;

            if (IsFlags)
            {
                // Skip initial spaces
                for (; i < stringValue.Length; i++)
                {
                    if (stringValue[i] != ' ')
                    {
                        break;
                    }
                }

                // Read space-delimited values
                int startIndex = i;
                int count      = 0;
                for (; i < stringValue.Length; i++)
                {
                    if (stringValue[i] == ' ')
                    {
                        count = i - startIndex;
                        if (count > 0)
                        {
                            longValue |= ReadEnumValue(stringValue, startIndex, count);
                        }
                        for (++i; i < stringValue.Length; i++)
                        {
                            if (stringValue[i] != ' ')
                            {
                                break;
                            }
                        }
                        startIndex = i;
                        if (i == stringValue.Length)
                        {
                            break;
                        }
                    }
                }
                count = i - startIndex;
                if (count > 0)
                {
                    longValue |= ReadEnumValue(stringValue, startIndex, count);
                }
            }
            else
            {
                if (stringValue.Length == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnRead, stringValue, DataContract.GetClrTypeFullName(UnderlyingType))));
                }
                longValue = ReadEnumValue(stringValue, 0, stringValue.Length);
            }

            if (IsULong)
            {
                return(Enum.ToObject(UnderlyingType, (object)(ulong)longValue));
            }
            return(Enum.ToObject(UnderlyingType, (object)longValue));
        }
예제 #47
0
        internal virtual object InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, string name, string ns)
        {
            DataContract dataContract = GetDataContract(declaredType);

            return(InternalDeserialize(xmlReader, name, ns, ref dataContract));
        }
예제 #48
0
 public void CheckEndOfArray(XmlReaderDelegator xmlReader, int arraySize, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
예제 #49
0
 public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context)
 {
     return((context == null) ? reader.ReadElementContentAsGuid()
         : HandleReadValue(reader.ReadElementContentAsGuid(), context));
 }
예제 #50
0
 protected virtual object ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
 {
     return(dataContract.ReadXmlValue(reader, this));
 }
예제 #51
0
 internal override object?InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
 {
     return(InternalReadObject(xmlReader, verifyObjectName, null));
 }
예제 #52
0
        internal void SkipUnknownElement(XmlReaderDelegator xmlReader)
#endif
        {
            ReadAttributes(xmlReader);
            xmlReader.Skip();
        }
예제 #53
0
 public void SkipUnknownElement(XmlReaderDelegator xmlReader)
예제 #54
0
 internal void HandleUnknownElement(XmlReaderDelegator xmlReader, ExtensionDataObject extensionData, int memberIndex)
 {
 }
예제 #55
0
 protected virtual bool IsReadingClassExtensionData(XmlReaderDelegator xmlReader)
 {
     return(false);
 }
예제 #56
0
 public static void Read(XmlReaderDelegator xmlReader)
예제 #57
0
        /*
         * The reason this function exists is to provide compatibility for ExceptionDataContract to utilize ClassDataContract for deserialization.
         * In order for ExceptionDataContract to deserialize using ClassDataContract the xml elements corresponding to private fields need
         * to have their name replaced with the name of the private field they map to.
         * Example: Message ---replaced to--> _message
         * 
         * Currently this method utilizes a custom created class entitled ExceptionXmlParser that sits alongside the ExceptionDataContract
         * The ExceptionXmlParser reads the xml string passed to it exchanges any element names that are presented in the name map
         * in its constructor.
         * 
         * The ExceptionXmlParser also gives each nested element the proper namespace for the given exception being deserialized.
         * The ClassDataContract needs an exact match on the element name and the namespace in order to deserialize the value, because not all serialization
         * explicitly inserts the xmlnamespace of nested objects, the exception xml parser handles this.
         */
        private XmlReaderDelegator ParseReaderString(XmlReaderDelegator xmlReader)
        {
            //The reference to the xmlReader passed into this method should not be modified.
            //The call to ReadOuterXml advances the xmlReader to the next object if the exception being parsed is a nested object of another class.
            //When the call to ReadXmlValue that called this method returns, it is possible that the 'xmlReader' will still be used by the calling datacontract.
            string EntryXmlString = xmlReader.UnderlyingReader.ReadOuterXml();

            string result = ExceptionXmlParser.ParseExceptionXmlForClassDataContract(ReverseDictionary(EssentialExceptionFields), this.Namespace.ToString(), EntryXmlString);

            byte[] byteBuffer = Encoding.UTF8.GetBytes(result);
            XmlReaderDelegator xmlDelegator = new XmlReaderDelegator(XmlDictionaryReader.CreateTextReader(byteBuffer, XmlDictionaryReaderQuotas.Max));

            xmlDelegator.MoveToContent();

            return xmlDelegator;
        }
예제 #58
0
 internal virtual object InternalReadObject(XmlReaderDelegator reader, bool verifyObjectName)
 {
     return(ReadObject(reader.UnderlyingReader, verifyObjectName));
 }
예제 #59
0
 public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
 {
     object o;
     if (context == null)
     {
         o = XmlObjectSerializerReadContext.ReadRootIXmlSerializable(xmlReader, this, true /*isMemberType*/);
     }
     else
     {
         o = context.ReadIXmlSerializable(xmlReader, this, true /*isMemberType*/);
         context.AddNewObject(o);
     }
     xmlReader.ReadEndElement();
     return o;
 }
예제 #60
0
 internal virtual object InternalReadObject(XmlReaderDelegator reader, bool verifyObjectName, DataContractResolver dataContractResolver)
 {
     return(InternalReadObject(reader, verifyObjectName));
 }