void IXmlSerializable.ReadXml(XmlReader r)
		{
			r.MoveToContent();
			r.ReadStartElement("Employee");
			
			 r.ReadStartElement("Name");
			 FirstName = r.ReadElementString("First", ns);
			 LastName = r.ReadElementString("Last", ns);
			r.ReadEndElement();
			r.MoveToContent();
			 ID = Int32.Parse(r.ReadElementString("ID", ns));
			 r.ReadEndElement();
			 
		}
        public static void ReadObject(XmlReader reader, object obj, PropertyConversionHandler handler = null)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");

            reader.MoveToContent();

            if (obj is IXmlSerializable)
            {
                ((IXmlSerializable)obj).ReadXml(reader);
            }
            else
            {
                object oVal = null;
                string oName = GetAttributeValue(obj.GetType(), typeof(XmlRootAttribute), "ElementName", true, ref oVal) ? oVal.ToString() : obj.GetType().Name;
                if (reader.LocalName != oName)
                    throw new XmlException("XML element name does not match object.");

                if (!reader.IsEmptyElement)
                {
                    reader.ReadStartElement();
                    reader.MoveToContent();
                    ReadObjectProperties(reader, obj, handler);
                    reader.ReadEndElement();
                }
                else
                    reader.Skip();
            }
        }
        public static void ReadObjectProperties(XmlReader reader, object obj, PropertyConversionHandler handler = null)
        {
            // Build property lookup table
            PropertyInfo[] props = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
            Dictionary<string, PropertyInfo> propHash = new Dictionary<string, PropertyInfo>(props.Length);
            foreach (var pi in props)
                if (!Attribute.IsDefined(pi, typeof(XmlIgnoreAttribute), false))
                    propHash.Add(GetPropertyElementName(pi), pi);

            while (reader.MoveToContent() == System.Xml.XmlNodeType.Element)
            {
                PropertyInfo pi;
                if (propHash.TryGetValue(reader.LocalName, out pi))
                {
                    if (IsStandardType(pi.PropertyType))
                    {
                        object value = null;
                        if (pi.PropertyType.IsEnum)
                            value = Enum.Parse(pi.PropertyType, reader.ReadElementContentAsString());
                        else
                            value = reader.ReadElementContentAs(pi.PropertyType, null);

                        if (handler != null)
                            handler(pi, obj, ref value);

                        pi.SetValue(obj, value, null);
                    }
                    else
                    {
                        ReadObject(reader, pi.GetValue(obj, null));
                    }
                }
                else
                {
                    reader.Skip();
                    reader.MoveToContent();
                }
            }
        }
Example #4
0
    private void _ParseFromReader(XmlReader reader)
    {
        reader.MoveToContent();

        string strToken;
        if (_GetToken(reader, out strToken) && strToken == "plist")
        {
            if (_NextToken(reader))
            {
                _ParseDictionary(reader);
            }
        }
        else
        {
            throw new FormatException("Badly format PLIST -- missing opening element");
        }
    }