当前位置: 首页>>代码示例>>C#>>正文


C# XmlReader.LineNumber方法代码示例

本文整理汇总了C#中XmlReader.LineNumber方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.LineNumber方法的具体用法?C# XmlReader.LineNumber怎么用?C# XmlReader.LineNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlReader的用法示例。


在下文中一共展示了XmlReader.LineNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWrittenType

 private static Type GetWrittenType(XmlReader reader, string elementName, Type objType)
 {
     var writtenTypeName = reader.GetAttribute("type");
     if (writtenTypeName == null) return GetSerializedType(objType);
     Type writtenType;
     if (!g_typeNameToType.TryGetValue(writtenTypeName, out writtenType))
     {
         writtenType = Type.GetType(writtenTypeName)
             ?? AppDomain.CurrentDomain.GetAssemblies()
                 .Select(assembly => assembly.GetType(writtenTypeName))
                 .Where(type => type != null)
                 .FirstOrDefault();
         if (writtenType == null)
             throw new XmlException("XML suggests unknown type " + writtenTypeName,
                 null, reader.LineNumber(), reader.LinePosition());
         g_typeNameToType.Add(writtenTypeName, writtenType);
     }
     if (!IsAssignableFrom(objType, writtenType))
         throw new XmlException("XML suggests type " + writtenTypeName + " that is not assignable to expected type " + objType.Name,
             null, reader.LineNumber(), reader.LinePosition());
     return writtenType;
 }
开发者ID:vvnurmi,项目名称:assaultwing,代码行数:22,代码来源:Serialization.cs

示例2: DeserializeFieldsAndPropertiesXml

 /// <summary>
 /// Reads in fields and properties of an object from an XML reader.
 /// </summary>
 /// <remarks>
 /// <para>
 /// You can limit the deserialisation to members that have the specified limitation attribute.
 /// This limitation is applied only to instances of classes that have 
 /// LimitedSerializationAttribute.
 ///</para>
 ///<para>
 /// The XML reader is assumed to be positioned on the first child element of 
 /// the root element of the serialised 'obj' to be read. At successful return, 
 /// the XML reader will be positioned at the end element of the serialised 'obj'.
 /// A log message is produced if an unknown serialised member is encountered.
 /// It is guaranteed that all fields and properties (marked with <paramref name="limitationAttribute"/>
 /// get a value exactly once, lest an exception is thrown.
 /// </para>
 /// </remarks>
 /// <param name="reader">Where to read the serialised values.</param>
 /// <param name="obj">The object whose members to deserialise.</param>
 /// <param name="limitationAttribute">Limit the deserialisation to members with this attribute,
 /// or deserialise all members if limitationAttribute is a null reference.</param>
 /// <seealso cref="AW2.Helpers.LimitedSerializationAttribute"/>
 private static void DeserializeFieldsAndPropertiesXml(XmlReader reader, object obj, Type limitationAttribute, bool tolerant)
 {
     try
     {
         var type = obj.GetType();
         var finder = new FieldAndPropertyFinder(obj.GetType(), limitationAttribute, tolerant);
         // NOTE: There is no guarantee about the order of the members.
         while (reader.IsStartElement())
         {
             var member = finder.Find(reader.Name);
             if (member == null)
             {
                 reader.Skip();
                 continue;
             }
             var memberLimitationAttribute = GetLimitationAttribute(member, limitationAttribute);
             var value = DeserializeXml(reader, reader.Name, member.ValueType, memberLimitationAttribute, tolerant);
             member.SetValue(obj, value);
         }
         finder.CheckForMissing();
     }
     catch (MemberSerializationException e)
     {
         e.LineNumber = reader.LineNumber();
         throw;
     }
 }
开发者ID:vvnurmi,项目名称:assaultwing,代码行数:50,代码来源:Serialization.cs


注:本文中的XmlReader.LineNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。