Init() private méthode

private Init ( XmlReader r, XmlDeserializationEvents events, string encodingStyle, TempAssembly tempAssembly ) : void
r XmlReader
events XmlDeserializationEvents
encodingStyle string
tempAssembly TempAssembly
Résultat void
        /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Deserialize5"]/*' />
        public object Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
        {
            events.sender = this;
            try {
                if (primitiveType != null)
                {
                    if (encodingStyle != null && encodingStyle.Length > 0)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEncodingNotEncoded1, encodingStyle));
                    }
                    return(DeserializePrimitive(xmlReader, events));
                }
                else if (tempAssembly == null || typedSerializer)
                {
                    XmlSerializationReader reader = CreateReader();
                    reader.Init(xmlReader, events, encodingStyle, tempAssembly);
                    try {
                        return(Deserialize(reader));
                    }
                    finally {
                        reader.Dispose();
                    }
                }
                else
                {
                    return(tempAssembly.InvokeReader(mapping, xmlReader, events, encodingStyle));
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (e is TargetInvocationException)
                {
                    e = e.InnerException;
                }

                if (xmlReader is IXmlLineInfo)
                {
                    IXmlLineInfo lineInfo = (IXmlLineInfo)xmlReader;
                    throw new InvalidOperationException(Res.GetString(Res.XmlSerializeErrorDetails, lineInfo.LineNumber.ToString(CultureInfo.InvariantCulture), lineInfo.LinePosition.ToString(CultureInfo.InvariantCulture)), e);
                }
                else
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlSerializeError), e);
                }
            }
            catch {
                if (xmlReader is IXmlLineInfo)
                {
                    IXmlLineInfo lineInfo = (IXmlLineInfo)xmlReader;
                    throw new InvalidOperationException(Res.GetString(Res.XmlSerializeErrorDetails, lineInfo.LineNumber.ToString(CultureInfo.InvariantCulture), lineInfo.LinePosition.ToString(CultureInfo.InvariantCulture)), null);
                }
                else
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlSerializeError), (Exception)null);
                }
            }
        }
        internal object InvokeReader(XmlMapping mapping, XmlReader xmlReader, XmlDeserializationEvents events, string encodingStyle)
        {
            XmlSerializationReader reader = null;

            try {
                encodingStyle = ValidateEncodingStyle(encodingStyle, mapping.Key);
                reader        = Contract.Reader;
                reader.Init(xmlReader, events, encodingStyle, this);
                if (methods[mapping.Key].readMethod == null)
                {
                    if (readerMethods == null)
                    {
                        readerMethods = Contract.ReadMethods;
                    }
                    string methodName = (string)readerMethods[mapping.Key];
                    if (methodName == null)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.XmlNotSerializable, mapping.Accessor.Name));
                    }
                    methods[mapping.Key].readMethod = GetMethodFromType(reader.GetType(), methodName, pregeneratedAssmbly ? this.assembly : null);
                }
                return(methods[mapping.Key].readMethod.Invoke(reader, emptyObjectArray));
            }
            catch (SecurityException e) {
                throw new InvalidOperationException(Res.GetString(Res.XmlNoPartialTrust), e);
            }
            finally {
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
        }
        /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Deserialize2"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public object Deserialize(XmlReader xmlReader)
        {
            try {
                if (tempAssembly == null)
                {
                    XmlSerializationReader reader = CreateReader();
                    reader.Init(xmlReader, events);
                    return(Deserialize(reader));
                }
                return(tempAssembly.InvokeReader(methodIndex, xmlReader, events));
            }
            catch (Exception e) {
                if (e is TargetInvocationException)
                {
                    e = e.InnerException;
                }

                if (xmlReader is XmlTextReader)
                {
                    XmlTextReader xmlTextReader = (XmlTextReader)xmlReader;
                    throw new InvalidOperationException(Res.GetString(Res.XmlSerializeErrorDetails, xmlTextReader.LineNumber.ToString(), xmlTextReader.LinePosition.ToString()), e);
                }
                else
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlSerializeError), e);
                }
            }
        }
Exemple #4
0
 internal object InvokeReader(XmlMapping mapping, XmlReader xmlReader, XmlDeserializationEvents events, string encodingStyle)
 {
     XmlSerializationReader reader = null;
     try
     {
         encodingStyle = ValidateEncodingStyle(encodingStyle, mapping.Key);
         reader = Contract.Reader;
         reader.Init(xmlReader, events, encodingStyle, this);
         if (_methods[mapping.Key].readMethod == null)
         {
             if (_readerMethods == null)
             {
                 _readerMethods = Contract.ReadMethods;
             }
             string methodName = (string)_readerMethods[mapping.Key];
             if (methodName == null)
             {
                 throw new InvalidOperationException(SR.Format(SR.XmlNotSerializable, mapping.Accessor.Name));
             }
             _methods[mapping.Key].readMethod = GetMethodFromType(reader.GetType(), methodName);
         }
         return _methods[mapping.Key].readMethod.Invoke(reader, Array.Empty<object>());
     }
     catch (SecurityException e)
     {
         throw new InvalidOperationException(SR.XmlNoPartialTrust, e);
     }
     finally
     {
         if (reader != null)
             reader.Dispose();
     }
 }
Exemple #5
0
        public object?Deserialize(XmlReader xmlReader, string?encodingStyle, XmlDeserializationEvents events)
        {
            events.sender = this;
            try
            {
                if (_primitiveType != null)
                {
                    if (encodingStyle != null && encodingStyle.Length > 0)
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlInvalidEncodingNotEncoded1, encodingStyle));
                    }
                    return(DeserializePrimitive(xmlReader, events));
                }
                else if (ShouldUseReflectionBasedSerialization(_mapping) || _isReflectionBasedSerializer)
                {
                    return(DeserializeUsingReflection(xmlReader, encodingStyle, events));
                }
                else if (_tempAssembly == null || _typedSerializer)
                {
                    XmlSerializationReader reader = CreateReader();
                    reader.Init(xmlReader, events, encodingStyle, _tempAssembly);
                    try
                    {
                        return(Deserialize(reader));
                    }
                    finally
                    {
                        reader.Dispose();
                    }
                }
                else
                {
                    return(_tempAssembly.InvokeReader(_mapping, xmlReader, events, encodingStyle));
                }
            }
            catch (Exception?e)
            {
                if (e is TargetInvocationException)
                {
                    e = e.InnerException;
                }

                if (xmlReader is IXmlLineInfo)
                {
                    IXmlLineInfo lineInfo = (IXmlLineInfo)xmlReader;
                    throw new InvalidOperationException(SR.Format(SR.XmlSerializeErrorDetails, lineInfo.LineNumber.ToString(CultureInfo.InvariantCulture), lineInfo.LinePosition.ToString(CultureInfo.InvariantCulture)), e);
                }
                else
                {
                    throw new InvalidOperationException(SR.XmlSerializeError, e);
                }
            }
        }
Exemple #6
0
        /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Deserialize5"]/*' />
        internal object Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
        {
#if FEATURE_LEGACYNETCF
            if (_legacyNetCFSerializer != null)
            {
                return(_legacyNetCFSerializer.Deserialize(xmlReader, encodingStyle));
            }
#endif

            try
            {
                if (_primitiveType != null)
                {
                    return(DeserializePrimitive(xmlReader, events));
                }
                else if (_tempAssembly == null || _typedSerializer)
                {
                    XmlSerializationReader reader = CreateReader();
                    reader.Init(xmlReader, events, encodingStyle, _tempAssembly);
                    try
                    {
                        return(Deserialize(reader));
                    }
                    finally
                    {
                        reader.Dispose();
                    }
                }
                else
                {
                    return(_tempAssembly.InvokeReader(_mapping, xmlReader, events, encodingStyle));
                }
            }
            catch (Exception e)
            {
                if (e is TargetInvocationException)
                {
                    e = e.InnerException;
                }

                if (xmlReader is IXmlLineInfo)
                {
                    IXmlLineInfo lineInfo = (IXmlLineInfo)xmlReader;
                    throw new InvalidOperationException(SR.Format(SR.XmlSerializeErrorDetails, lineInfo.LineNumber.ToString(CultureInfo.InvariantCulture), lineInfo.LinePosition.ToString(CultureInfo.InvariantCulture)), e);
                }
                else
                {
                    throw new InvalidOperationException(SR.XmlSerializeError, e);
                }
            }
        }
        public object Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
        {
            object obj2;

            events.sender = this;
            try
            {
                if (this.primitiveType != null)
                {
                    if ((encodingStyle != null) && (encodingStyle.Length > 0))
                    {
                        throw new InvalidOperationException(Res.GetString("XmlInvalidEncodingNotEncoded1", new object[] { encodingStyle }));
                    }
                    return(this.DeserializePrimitive(xmlReader, events));
                }
                if ((this.tempAssembly == null) || this.typedSerializer)
                {
                    XmlSerializationReader reader = this.CreateReader();
                    reader.Init(xmlReader, events, encodingStyle, this.tempAssembly);
                    try
                    {
                        return(this.Deserialize(reader));
                    }
                    finally
                    {
                        reader.Dispose();
                    }
                }
                obj2 = this.tempAssembly.InvokeReader(this.mapping, xmlReader, events, encodingStyle);
            }
            catch (Exception innerException)
            {
                if (((innerException is ThreadAbortException) || (innerException is StackOverflowException)) || (innerException is OutOfMemoryException))
                {
                    throw;
                }
                if (innerException is TargetInvocationException)
                {
                    innerException = innerException.InnerException;
                }
                if (xmlReader is IXmlLineInfo)
                {
                    IXmlLineInfo info = (IXmlLineInfo)xmlReader;
                    throw new InvalidOperationException(Res.GetString("XmlSerializeErrorDetails", new object[] { info.LineNumber.ToString(CultureInfo.InvariantCulture), info.LinePosition.ToString(CultureInfo.InvariantCulture) }), innerException);
                }
                throw new InvalidOperationException(Res.GetString("XmlSerializeError"), innerException);
            }
            return(obj2);
        }
Exemple #8
0
        public object InvokeReader(int methodIndex, XmlReader xmlReader, XmlDeserializationEvents events)
        {
            if (!allAssembliesAllowPartialTrust)
            {
                new PermissionSet(PermissionState.Unrestricted).Demand();
            }
            XmlSerializationReader reader = (XmlSerializationReader)Activator.CreateInstance(readerType);

            reader.Init(xmlReader, events);
            ResolveEventHandler resolver = new ResolveEventHandler(this.OnAssemblyResolve);

            assemblyResolveThread = Thread.CurrentThread.GetHashCode();
            AppDomain.CurrentDomain.AssemblyResolve += resolver;
            object ret = methods[methodIndex].readMethod.Invoke(reader, emptyObjectArray);

            AppDomain.CurrentDomain.AssemblyResolve -= resolver;
            assemblyResolveThread = 0;
            return(ret);
        }
        internal object InvokeReader(int methodIndex, XmlReader xmlReader, XmlDeserializationEvents events, string encodingStyle)
        {
            XmlSerializationReader reader = null;

            try {
                encodingStyle = ValidateEncodingStyle(encodingStyle, methodIndex);
                reader        = (XmlSerializationReader)Activator.CreateInstance(readerType);
                reader.Init(xmlReader, events, encodingStyle, this);

                return(methods[methodIndex].readMethod.Invoke(reader, emptyObjectArray));
            }
            catch (SecurityException e) {
                throw new InvalidOperationException(Res.GetString(Res.XmlNoPartialTrust), e);
            }
            finally {
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
        }