示例#1
0
        /// <summary>
        /// Tries to deserialized instance of <see cref="ServiceResourceError"/> to its object equivalent.
        /// A return value indicates whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="input">A stream that contains a serialized instance of <see cref="ServiceResourceError"/> to convert.</param>
        /// <param name="result">When the method returns, contains the deserialized <see cref="ServiceResourceError"/> object,
        /// if the conversion succeeded, or <c>null</c>, if the conversion failed.</param>
        /// <returns><c>true</c> if the input parameter is successfully converted; otherwise, <c>false</c>.</returns>
        public static bool TryParse(string input, out ServiceResourceError result)
        {
            result = null;

            if (input == null)
            {
                return(false);
            }

            // Deserialize the stream using DataContractSerializer.
            try
            {
                using (XmlDictionaryReader xmlReader = XmlDictionaryReader.CreateTextReader(
                           Encoding.UTF8.GetBytes(input),
                           new XmlDictionaryReaderQuotas()))
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(ServiceResourceError));
                    result = (ServiceResourceError)serializer.ReadObject(xmlReader, true);
                    return(true);
                }
            }
            catch (Exception)
            {
            }

            return(false);
        }
        /// <summary>
        /// Tries to deserialized instance of <see cref="ServiceResourceError"/> to its object equivalent.
        /// A return value indicates whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="input">A stream that contains a serialized instance of <see cref="ServiceResourceError"/> to convert.</param>
        /// <param name="result">When the method returns, contains the deserialized <see cref="ServiceResourceError"/> object,
        /// if the conversion succeeded, or <c>null</c>, if the conversion failed.</param>
        /// <returns><c>true</c> if the input parameter is successfully converted; otherwise, <c>false</c>.</returns>
        public static bool TryParse(string input, out ServiceResourceError result)
        {
            result = null;

            if (input == null)
            {
                return false;
            }

            // Deserialize the stream using DataContractSerializer.
            try
            {
                using (XmlDictionaryReader xmlReader = XmlDictionaryReader.CreateTextReader(
                    Encoding.UTF8.GetBytes(input),
                    new XmlDictionaryReaderQuotas()))
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(ServiceResourceError));
                    result = (ServiceResourceError)serializer.ReadObject(xmlReader, true);
                    return true;
                }
            }
            catch (Exception)
            {
            }

            return false;
        }