ReaderDelegate ReadComplex(DynamicMember member, string name, object defaultValue)
 {
     EQXSerializer serializer = EQXSerializer.GetSerializer(member.MemberType);
     return (XPathNavigator navigator, ref object target) =>
     {
         XPathNavigator datanav = navigator.SelectSingleNode(name);
         if (datanav != null && !datanav.IsEmptyElement)
         {
             object value = null;
             serializer.Deserialize(datanav, ref value);
             member.SetValue(ref target, value);
         }
         else if (defaultValue != null)
             member.SetValue(ref target, defaultValue);
     };
 }
        ReaderDelegate ReadPrimitive(DynamicMember member, string name, object defaultValue)
        {
            return (XPathNavigator navigator, ref object target) =>
            {
                XPathNavigator datanav = navigator.SelectSingleNode(name);
                if (datanav != null && !datanav.IsEmptyElement)
                {
                    object value = null;
                    try { value = datanav.ValueAs(member.MemberType); }
                    catch (FormatException e)
                    {
                        // fixing sloppy dev typos, YAY!

                        if (member.MemberType == typeof(bool))
                        {
                            bool b;
                            if (bool.TryParse(datanav.Value.ToLower(), out b))
                                value = b;
                            else
                                value = false;
                        }
                        else if (member.MemberType == typeof(int))
                        {
                            string val = datanav.Value;
                            if (val.EndsWith("+"))
                                val = val.Replace("+", "");

                            int i;
                            if (int.TryParse(val, out i))
                                value = i;
                            else
                                value = 0;
                        }
                        else
                            throw e;
                    }

                    member.SetValue(ref target, value);
                }
                else if (defaultValue != null)
                    member.SetValue(ref target, defaultValue);
            };
        }
        ReaderDelegate ReadArray(DynamicMember member, string name, string itemName, object defaultValue)
        {
            EQXSerializer serializer = EQXSerializer.GetSerializer(member.ArrayItemType);

            if (!string.IsNullOrEmpty(itemName))
            {
                return (XPathNavigator navigator, ref object target) =>
                {
                    XPathNodeIterator it = null;
                    XPathNavigator datanav = navigator.SelectSingleNode(name);
                    if (datanav != null && !datanav.IsEmptyElement)
                        it = datanav.Select(string.Concat("./", itemName));

                    if (it != null && it.Count > 0)
                    {
                        IList value = Activator.CreateInstance(member.MemberType, it.Count) as IList;
                        int i = 0;
                        while (it.MoveNext())
                        {
                            XPathNavigator itemnav = it.Current;
                            if (itemnav != null && !itemnav.IsEmptyElement)
                            {
                                object itemValue = null;
                                serializer.Deserialize(itemnav, ref itemValue);
                                value[i++] = itemValue;
                            }
                        }
                        member.SetValue(ref target, value);
                    }
                    else
                        member.SetValue(ref target, defaultValue);
                };
            }
            return (XPathNavigator navigator, ref object target) =>
            {
                XPathNodeIterator it = null;
                if (itemName == null)
                    it = navigator.Select("./" + name);
                else
                {
                    XPathNavigator datanav = navigator.SelectSingleNode(name);
                    if (datanav != null && !datanav.IsEmptyElement)
                        it = datanav.Select("./" + itemName);
                }

                if (it != null && it.Count > 0)
                {
                    IList value = Activator.CreateInstance(member.MemberType, it.Count) as IList;
                    int i = 0;
                    while (it.MoveNext())
                    {
                        XPathNavigator itemnav = it.Current;
                        if (itemnav != null && !itemnav.IsEmptyElement)
                        {
                            object itemValue = null;
                            serializer.Deserialize(itemnav, ref itemValue);
                            value[i++] = itemValue;
                        }
                    }
                    member.SetValue(ref target, value);
                }
            };
        }