public static Amqp.Types.Map NMSMapToAmqp(IPrimitiveMap nmsmap)
        {
            if (nmsmap == null)
            {
                return(null);
            }
            Amqp.Types.Map result = new Amqp.Types.Map();
            if (nmsmap is Map.AMQP.AMQPValueMap)
            {
                return((nmsmap as Map.AMQP.AMQPValueMap).AmqpMap);
            }
            else
            {
                foreach (string key in nmsmap.Keys)
                {
                    object value = nmsmap[key];

                    if (value is IDictionary)
                    {
                        value = ConversionSupport.MapToAmqp(value as IDictionary);
                    }
                    else if (value is IList)
                    {
                        value = ConversionSupport.ListToAmqp(value as IList);
                    }

                    result[key] = value;
                    //Tracer.InfoFormat("Conversion key : {0}, value : {1}, valueType: {2} nmsValue: {3}, nmsValueType: {4}.",
                    //    key, value, value.GetType().Name, );
                }
            }
            return(result);
        }
        public static Amqp.Types.Map MapToAmqp(IDictionary dictionary)
        {
            if (dictionary == null)
            {
                return(null);
            }

            /*if (dictionary is Amqp.Types.Map)
             * {
             *  Amqp.Types.Map DictMap = dictionary as Amqp.Types.Map;
             *
             *  return DictMap.Clone() as Amqp.Types.Map;
             * }*/
            Amqp.Types.Map map      = new Amqp.Types.Map();
            IEnumerator    iterator = dictionary.Keys.GetEnumerator();

            iterator.MoveNext();
            object key = iterator.Current;

            if (key == null)
            {
                return(null);
            }
            object value = null;

            do
            {
                value = dictionary[key];
                if (value != null)
                {
                    Type valtype = value.GetType();
                    if (value is IDictionary)
                    {
                        map[key] = ConversionSupport.MapToAmqp(value as IDictionary);
                    }
                    else if (value is IList)
                    {
                        map[key] = ConversionSupport.ListToAmqp(value as IList);
                    }
                    else if (IsNMSType(value))
                    //else if (valtype.IsPrimitive || value is byte[] || value is String)
                    {
                        map[key] = value;
                    }
                    else
                    {
                        Tracer.InfoFormat("Failed to convert IDictionary[{0}], value{1} to Map value: Invalid Type: {2}",
                                          key, value.ToString(), valtype.Name);
                    }
                }
            }while (iterator.MoveNext() && (key = iterator.Current) != null);
            return(map);
        }
        public static IList ListToAmqp(IList ilist)
        {
            if (ilist == null)
            {
                return(null);
            }
            //
            // Special case for Byte[] which has the iList interface, we
            // don't want to convert Byte[] to a List so just return a copy.
            // Return a copy because it may be added to a List or Dictionary as
            // a reference, which will arrive here, and we want to be sure we have
            // our own copy after return.
            if (ilist is Byte[])
            {
                byte[] copy = new byte[(ilist as Byte[]).Length];
                Array.Copy(ilist as Byte[], 0, copy, 0, (ilist as Byte[]).Length);
                return(copy);
            }
            List list = new List();

            foreach (object o in ilist)
            {
                object value = o;
                if (o != null)
                {
                    Type valtype = value.GetType();
                    if (value is IDictionary)
                    {
                        value = ConversionSupport.MapToAmqp(value as IDictionary);
                    }
                    else if (value is IList)
                    {
                        value = ConversionSupport.ListToAmqp(value as IList);
                    }
                    else if (ConversionSupport.IsNMSType(value))
                    //else if (valtype.IsPrimitive || value is byte[] || value is String)
                    {
                        // do nothing
                        // value = value;
                    }
                    else
                    {
                        Tracer.InfoFormat("Failed to convert IList to amqp List value({0}): Invalid Type: {1}",
                                          value.ToString(), valtype.Name);
                    }
                }
                list.Add(value);
            }
            return(list);
        }