Apache.NMS.Util.XmlUtil.Deserialize C# (CSharp) Method

Deserialize() public static method

public static Deserialize ( Type objType, string text ) : object
objType System.Type
text string
return object
        public static object Deserialize(Type objType, string text)
        {
            if(null == text)
            {
                return null;
            }

            try
            {
                XmlSerializer serializer = new XmlSerializer(objType);

                // Set the error handlers.
                serializer.UnknownNode += serializer_UnknownNode;
                serializer.UnknownElement += serializer_UnknownElement;
                serializer.UnknownAttribute += serializer_UnknownAttribute;
                return serializer.Deserialize(new StringReader(text));
            }
            catch(Exception ex)
            {
                Tracer.ErrorFormat("Error deserializing object: {0}", ex.Message);
                return null;
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Deserialize the object from the text message.  The object must be serializable from XML.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        internal static object DeserializeObjFromMessage(IMessage message)
        {
            ITextMessage textMessage = message as ITextMessage;

            if (null == textMessage)
            {
                return(null);
            }

            if (null == textMessage.NMSType || textMessage.NMSType.Length < 1)
            {
                Tracer.ErrorFormat("NMSType not set on message.  Could not deserializing XML object.");
                return(null);
            }

            Type objType = GetRuntimeType(textMessage.NMSType);

            if (null == objType)
            {
                Tracer.ErrorFormat("Could not load type for {0} while deserializing XML object.", textMessage.NMSType);
                return(null);
            }

            return(XmlUtil.Deserialize(objType, textMessage.Text));
        }
All Usage Examples Of Apache.NMS.Util.XmlUtil::Deserialize