示例#1
0
        public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
        {
            xmlReader.Read();
            Type   objType = UnderlyingType;
            object obj     = objType.IsArray ? Array.CreateInstance(objType.GetElementType(), 0) : GetUninitializedObject(objType);

            context.AddNewObject(obj);
            string            objectId = context.GetObjectId();
            SerializationInfo serInfo  = context.ReadSerializationInfo(xmlReader, objType);
            object            newObj   = SerializationSurrogateSetObjectData(obj, serInfo, context.GetStreamingContext());

            if (newObj == null)
            {
                newObj = obj;
            }

            if (newObj is IDeserializationCallback)
            {
                ((IDeserializationCallback)newObj).OnDeserialization(null);
            }

            if (newObj is IObjectReference)
            {
                newObj = GetRealObject((IObjectReference)newObj, context.GetStreamingContext());
            }

            context.ReplaceDeserializedObject(objectId, obj, newObj);
            xmlReader.ReadEndElement();
            return(newObj);
        }
 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;
 }
        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 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;
		}
示例#5
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;
 }
        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;
        }
示例#7
0
 protected static object HandleReadValue(object obj, XmlObjectSerializerReadContext context)
 {
     context.AddNewObject(obj);
     return obj;
 }
示例#8
0
 protected static object HandleReadValue(object obj, XmlObjectSerializerReadContext context)
 {
     context.AddNewObject(obj);
     return(obj);
 }
示例#9
0
 public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
 {
     object obj = ReadEnumValue(xmlReader);
     if (context != null)
         context.AddNewObject(obj);
     return obj;
 }