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);
        }
Beispiel #2
0
        private static object ResolveAdapterObject(object obj, ClassDataContract classContract)
        {
            Type objType = obj.GetType();

            if (objType == Globals.TypeOfDateTimeOffsetAdapter)
            {
                obj = DateTimeOffsetAdapter.GetDateTimeOffset((DateTimeOffsetAdapter)obj);
            }
            else if (obj is IKeyValuePairAdapter)
            {
                obj = classContract.GetKeyValuePairMethodInfo.Invoke(obj, Array.Empty <object>());
            }

            return(obj);
        }