public static MessageAttributeValueUnmarshaller GetInstance()
 {
     if (instance == null)
     {
         instance = new MessageAttributeValueUnmarshaller();
     }
     return(instance);
 }
        public Message Unmarshall(XmlUnmarshallerContext context)
        {
            Message unmarshalledObject = new Message();
            int     originalDepth      = context.CurrentDepth;
            int     targetDepth        = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Attribute", targetDepth))
                    {
                        var unmarshaller = new KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.GetInstance(), StringUnmarshaller.GetInstance());
                        var item         = unmarshaller.Unmarshall(context);
                        unmarshalledObject.Attributes.Add(item);
                        continue;
                    }
                    if (context.TestExpression("Body", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.GetInstance();
                        unmarshalledObject.Body = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("MD5OfBody", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.GetInstance();
                        unmarshalledObject.MD5OfBody = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("MD5OfMessageAttributes", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.GetInstance();
                        unmarshalledObject.MD5OfMessageAttributes = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("MessageAttribute", targetDepth))
                    {
                        var unmarshaller = new KeyValueUnmarshaller <string, MessageAttributeValue, StringUnmarshaller, MessageAttributeValueUnmarshaller>(StringUnmarshaller.GetInstance(), MessageAttributeValueUnmarshaller.GetInstance());
                        var item         = unmarshaller.Unmarshall(context);
                        unmarshalledObject.MessageAttributes.Add(item);
                        continue;
                    }
                    if (context.TestExpression("MessageId", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.GetInstance();
                        unmarshalledObject.MessageId = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("ReceiptHandle", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.GetInstance();
                        unmarshalledObject.ReceiptHandle = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return(unmarshalledObject);
                }
            }

            return(unmarshalledObject);
        }