本文整理汇总了C#中XmlReader.MoveToContent方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.MoveToContent方法的具体用法?C# XmlReader.MoveToContent怎么用?C# XmlReader.MoveToContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlReader
的用法示例。
在下文中一共展示了XmlReader.MoveToContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
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();
}
示例2: ReadObject
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();
}
}
示例3: ReadObjectProperties
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();
}
}
}
示例4: _ParseFromReader
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");
}
}