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


C# XmlReader.ReadElementContentAs方法代码示例

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


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

示例1: ReadXml

		internal static ResolveCriteria ReadXml (XmlReader reader, DiscoveryVersion version)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");

			var ret = new ResolveCriteria ();

			reader.MoveToContent ();
			if (!reader.IsStartElement ("ResolveType", version.Namespace) || reader.IsEmptyElement)
				throw new XmlException ("Non-empty ResolveType element is expected");
			reader.ReadStartElement ("ResolveType", version.Namespace);

			// standard members
			reader.MoveToContent ();
			ret.Address = EndpointAddress.ReadFrom (version.MessageVersion.Addressing, reader);

			// non-standard members
			for (reader.MoveToContent (); !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
				if (reader.NamespaceURI == SerializationNS) {
					switch (reader.LocalName) {
					case "Duration":
						ret.Duration = (TimeSpan) reader.ReadElementContentAs (typeof (TimeSpan), null);
						break;
					}
				}
				else
					ret.Extensions.Add (XElement.Load (reader));
			}

			reader.ReadEndElement ();

			return ret;
		}
开发者ID:nickchal,项目名称:pash,代码行数:33,代码来源:ResolveCriteria.cs

示例2: DeserializeElement

        protected override void DeserializeElement(XmlReader reader, bool s)
        {
            // ReSharper disable AssignNullToNotNullAttribute
            Value = reader.ReadElementContentAs(typeof(string), null) as string;
            // ReSharper restore AssignNullToNotNullAttribute

            if (Value != null) Value = Value.Trim();
        }
开发者ID:kirkpabk,项目名称:higgs,代码行数:8,代码来源:CDataElement.cs

示例3: ReadXml

		internal static EndpointDiscoveryMetadata ReadXml (XmlReader reader, DiscoveryVersion version)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");

			var ret = new EndpointDiscoveryMetadata ();

			reader.MoveToContent ();

			reader.ReadStartElement ();
			reader.MoveToContent ();

			// standard members
			reader.MoveToContent ();

			// it is possible due to InternalVisibleToAttribute...
			string addrNS = version.MessageVersion.Addressing.Namespace;

			ret.Address = EndpointAddress.ReadFrom (version.MessageVersion.Addressing, reader, "EndpointReference", addrNS);

			reader.MoveToContent ();
			if (reader.IsStartElement ("Types", version.Namespace))
				ret.ContractTypeNames = new Collection<XmlQualifiedName> ((XmlQualifiedName []) reader.ReadElementContentAs (typeof (XmlQualifiedName []), null, "Types", version.Namespace));

			reader.MoveToContent ();
			if (reader.IsStartElement ("Scopes", version.Namespace))
				ret.Scopes = new Collection<Uri> ((Uri []) reader.ReadElementContentAs (typeof (Uri []), null, "Scopes", version.Namespace));

			if (reader.IsStartElement ("XAddrs", version.Namespace))
				ret.ListenUris = new Collection<Uri> ((Uri []) reader.ReadElementContentAs (typeof (Uri []), null, "XAddrs", version.Namespace));

			if (reader.IsStartElement ("MetadataVersion", version.Namespace))
				ret.Version = reader.ReadElementContentAsInt ();

			// non-standard members
			for (reader.MoveToContent (); !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ())
				ret.Extensions.Add (XElement.Load (reader));

			reader.ReadEndElement ();

			return ret;
		}
开发者ID:nickchal,项目名称:pash,代码行数:42,代码来源:EndpointDiscoveryMetadata.cs

示例4: ReadXml

		internal static EndpointDiscoveryMetadata ReadXml (XmlReader reader, DiscoveryVersion version)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");

			var ret = new EndpointDiscoveryMetadata ();

			reader.MoveToContent ();
			if (!reader.IsStartElement ("ProbeMatchType", version.Namespace) || reader.IsEmptyElement)
				throw new XmlException ("Non-empty ProbeMatchType element is expected");
			reader.ReadStartElement ("ProbeType", version.Namespace);

			// standard members
			reader.MoveToContent ();
			ret.Address = EndpointAddress.ReadFrom (AddressingVersion.WSAddressing10, reader);

			reader.MoveToContent ();
			bool isEmpty = reader.IsEmptyElement;
			ret.ContractTypeNames = new Collection<XmlQualifiedName> ((XmlQualifiedName []) reader.ReadElementContentAs (typeof (XmlQualifiedName []), null, "Types", version.Namespace));

			reader.MoveToContent ();
			if (reader.IsStartElement ("Scopes", version.Namespace))
				ret.Scopes = new Collection<Uri> ((Uri []) reader.ReadElementContentAs (typeof (Uri []), null, "Scopes", version.Namespace));

			if (reader.IsStartElement ("XAddrs", version.Namespace))
				ret.ListenUris = new Collection<Uri> ((Uri []) reader.ReadElementContentAs (typeof (Uri []), null, "XAddrs", version.Namespace));

			if (reader.IsStartElement ("MetadataVersion", version.Namespace))
				ret.Version = reader.ReadElementContentAsInt ();

			// non-standard members
			for (reader.MoveToContent (); !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ())
				ret.Extensions.Add (XElement.Load (reader));

			reader.ReadEndElement ();

			return ret;
		}
开发者ID:afaerber,项目名称:mono,代码行数:38,代码来源:EndpointDiscoveryMetadata.cs

示例5: DeserializeElement

 protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
 {
     var props = Properties;
     if (reader.AttributeCount > 0)
     {
         while (reader.MoveToNextAttribute())
         {
             var propertyName = reader.Name;
             var xmlValue = reader.Value;
             var prop = props[propertyName];
             var propertyValue = prop.Converter.ConvertFromInvariantString(xmlValue);
             base[propertyName] = propertyValue;
         }
     }
     reader.MoveToContent();
     var content = reader.ReadElementContentAs(typeof(string), null);
     if (content != null)
         Sql = ((string)content).Trim();
 }
开发者ID:jhgbrt,项目名称:DbMigrations,代码行数:19,代码来源:QueryConfigurationElement.cs

示例6: ParseBlock

 private void ParseBlock(ref List<MemoryBlock> list, ref XmlReader reader)
 {
     MemoryBlock MemBlock = new MemoryBlock();
     reader.ReadToFollowing("m_block_base_addr");
     MemBlock.BlockAddress = (UInt64)reader.ReadElementContentAs(typeof(UInt64), null);
     reader.ReadToNextSibling("protection");
     MemBlock.BlockProtection = (UInt32)reader.ReadElementContentAs(typeof(UInt32), null);
     reader.ReadToNextSibling("m_size");
     MemBlock.BlockSize = (UInt64)reader.ReadElementContentAs(typeof(UInt64), null);
     reader.ReadToNextSibling("m_storage_type");
     MemBlock.BlockStorageType = (UInt32)reader.ReadElementContentAs(typeof(UInt32), null);
     reader.ReadToNextSibling("m_is_shared");
     MemBlock.IsShared = (Boolean)reader.ReadElementContentAs(typeof(Boolean), null);
     reader.ReadToNextSibling("m_map_file_name");
     MemBlock.MappedFileName = (String)reader.ReadElementContentAs(typeof(String), null);
     list.Add(MemBlock);
 }
开发者ID:kreuzerkrieg,项目名称:CPPJunk,代码行数:17,代码来源:MemoryDataXmlParser.cs

示例7: DeserializeElement

 /// <summary>
 /// Deserializes the element.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="s">if set to <c>true</c> [s].</param>
 protected override void DeserializeElement(XmlReader reader, bool s)
 {
     this.Value = reader.ReadElementContentAs(typeof(string), null) as string;
 }
开发者ID:TheHunter,项目名称:WcfExtensions,代码行数:9,代码来源:ConfigTextElement.cs

示例8: ReadXml

		internal static FindCriteria ReadXml (XmlReader reader, DiscoveryVersion version)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");

			var ret = new FindCriteria ();

			reader.MoveToContent ();
			if (!reader.IsStartElement ("Probe", version.Namespace) || reader.IsEmptyElement)
				throw new XmlException (String.Format ("Non-empty ProbeType element is expected. Got '{0}' {1} node in namespace '{2}' instead.", reader.LocalName, reader.NodeType, reader.NamespaceURI));
			reader.ReadStartElement ("Probe", version.Namespace);

			// standard members
			reader.MoveToContent ();
			if (reader.IsStartElement ("Types", version.Namespace))
				ret.ContractTypeNames = new Collection<XmlQualifiedName> ((XmlQualifiedName []) reader.ReadElementContentAs (typeof (XmlQualifiedName []), null, "Types", version.Namespace));

			reader.MoveToContent ();
			if (reader.IsStartElement ("Types", version.Namespace)) {
				if (reader.MoveToAttribute ("MatchBy")) {
					ret.ScopeMatchBy = new Uri (reader.Value, UriKind.RelativeOrAbsolute);
					reader.MoveToElement ();
				}
				ret.Scopes = new Collection<Uri> ((Uri []) reader.ReadElementContentAs (typeof (Uri []), null, "Scopes", version.Namespace));
			}

			// non-standard members
			for (reader.MoveToContent (); !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
				if (reader.NamespaceURI == SerializationNS) {
					switch (reader.LocalName) {
					case "MaxResults":
						ret.MaxResults = reader.ReadElementContentAsInt ();
						break;
					case "Duration":
						ret.Duration = (TimeSpan) reader.ReadElementContentAs (typeof (TimeSpan), null);
						break;
					}
				}
				else
					ret.Extensions.Add (XElement.Load (reader));
			}

			reader.ReadEndElement ();

			return ret;
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:46,代码来源:FindCriteria.cs

示例9: SoapDeserializeValue

 /// <summary>
 /// Deserializes the contents of the given XML <paramref name="reader"/>'s current element in the formatting rules
 /// given by this data type.
 /// </summary>
 /// <param name="reader">XML reader whose current element's value will be deserialized.
 /// The reader's position is the start of the parent element, the result should go. After this method returns, the reader
 /// must have read the end element.</param>
 /// <returns>Deserialized object of this data type (may be <c>null</c>).</returns>
 public object SoapDeserializeValue(XmlReader reader)
 {
   object result;
   if (SoapHelper.ReadNull(reader))
     result = null;
   else
   {
     switch (_upnpTypeName)
     {
       case "ui1":
       case "ui2":
       case "ui4":
       case "ui8":
       case "i1":
       case "i2":
       case "i4":
       case "i8":
       case "int":
       case "r4":
       case "r8":
       case "number":
       case "fixed.14.4":
       case "float":
       case "char":
         result = reader.ReadElementContentAs(_dotNetType, null);
         break;
       case "string":
       case "uuid":
         result = reader.ReadElementContentAsString();
         break;
       case "date":
         result = System.DateTime.ParseExact(reader.ReadElementContentAsString(), "yyyy-MM-dd", null);
         break;
       case "dateTime":
         result = System.DateTime.ParseExact(reader.ReadElementContentAsString(), "s", null);
         break;
       case "dateTime.tz":
         result = System.DateTime.ParseExact(reader.ReadElementContentAsString(), "u", null).ToLocalTime();
         break;
       case "time":
         result = System.DateTime.ParseExact(reader.ReadElementContentAsString(), "T", null);
         break;
       case "time.tz":
         result = System.DateTime.ParseExact(reader.ReadElementContentAsString(), "hh:mm:ss", null).ToLocalTime();
         break;
       case "boolean":
         result = reader.ReadElementContentAs(_dotNetType, null);
         break;
       case "bin.base64":
         result = reader.ReadElementContentAs(_dotNetType, null);
         break;
       case "bin.hex":
         result = EncodingUtils.FromHexString(reader.ReadElementContentAsString());
         break;
       case "uri":
         result = new Uri(reader.ReadElementContentAsString());
         break;
       default:
         throw new NotImplementedException(string.Format("UPnP standard data type '{0}' is not implemented", _upnpTypeName));
     }
     // Reader will already have read the end element in the methods ReadElementContentXXX
   }
   return result;
 }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:72,代码来源:UPnPStandardDataType.cs

示例10: ReadValue

        private static object ReadValue(XmlReader reader, Type objectType, string name)
        {
            object value = null;
            var hasValue = false;
            if (name != null && reader.HasAttributes)
            {
                var attrValue = reader.GetAttribute(name);
                hasValue = !string.IsNullOrEmpty(attrValue);
                attrValue.TryParse(objectType, out value);
            }

            if (!hasValue)
            {
                value = reader.ReadElementContentAs(objectType, null);
            }
            return value;
        }
开发者ID:ulrakhma,项目名称:Nemo,代码行数:17,代码来源:XmlSerializationReader.cs

示例11: DeserializeElement

 protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
 {
     Value = (string)reader.ReadElementContentAs(typeof(string), null);
 }
开发者ID:geffzhang,项目名称:LogSearchShipper,代码行数:4,代码来源:FileWatchElement.cs

示例12: ParseRegion

 private void ParseRegion(ref MemoryRegion region, ref XmlReader reader)
 {
     reader.ReadToDescendant("m_region_base_addr");
     region.RegionAddress = (UInt64)reader.ReadElementContentAs(typeof(UInt64), null);
     reader.ReadToNextSibling("m_region_protection");
     region.RegionProtection = (UInt32)reader.ReadElementContentAs(typeof(UInt32), null);
     reader.ReadToNextSibling("region_size");
     region.RegionSize = (UInt64)reader.ReadElementContentAs(typeof(UInt64), null);
     reader.ReadToNextSibling("m_storage_type");
     region.RegionStorageType = (UInt32)reader.ReadElementContentAs(typeof(UInt32), null);
     reader.ReadToNextSibling("m_region_blocks");
     region.NumberOfBlocks = (UInt32)reader.ReadElementContentAs(typeof(UInt32), null);
     reader.ReadToNextSibling("m_guard_blocks");
     region.NumberOfGuardBlocks = (UInt32)reader.ReadElementContentAs(typeof(UInt32), null);
     reader.ReadToNextSibling("m_is_stack");
     region.IsAStack = (Boolean)reader.ReadElementContentAs(typeof(Boolean), null);
     reader.ReadToFollowing("m_blocks");
     XmlReader SubReader = reader.ReadSubtree();
     ParseBlocks(ref region.MemoryBlocks, ref SubReader);
 }
开发者ID:kreuzerkrieg,项目名称:CPPJunk,代码行数:20,代码来源:MemoryDataXmlParser.cs

示例13: ParseBlocks

 private void ParseBlocks(ref List<MemoryBlock> list, ref XmlReader reader)
 {
     reader.ReadToFollowing("count");
     UInt32 ListLength = (UInt32)reader.ReadElementContentAs(typeof(UInt32), null);
     if (ListLength == 0)
         return;
     list = new List<MemoryBlock>();
     while (reader.ReadToFollowing("item"))
     {
         XmlReader SubReader = reader.ReadSubtree();
         ParseBlock(ref list, ref SubReader);
     }
 }
开发者ID:kreuzerkrieg,项目名称:CPPJunk,代码行数:13,代码来源:MemoryDataXmlParser.cs

示例14: ReadXml

        /// <summary>
        /// Deserializes the current BusinessObject from a XML stream.
        /// </summary>
        /// <param name="r">Active XML stream reader.</param>
        /// <remarks>Reads the outer element. Leaves the reader at the same depth.</remarks>
        // TODO Clear properties before reading from file
        public virtual void ReadXml(XmlReader r)
        {
            var props = GetAllDataProperties().ToList();
            r.ReadStartElement();
            while (r.NodeType == XmlNodeType.Element) {

                var prop = props.FirstOrDefault(n => n.Name.Equals(r.Name));
                if (prop == null) {
                    // ignore unknown property.
                    r.Skip();
                    continue;
                }

                var propertyType = prop.PropertyType;
                var propertyValue = prop.GetValue(this, null);

                // if property type is BusinessObject, let it auto-load from XML.
                if (typeof(BusinessObject).IsAssignableFrom(propertyType)) {
                    ((BusinessObject)propertyValue).ReadXml(r);
                    continue;
                }

                // if property type is List<T>, assume it's of BusinessObjects and try to fetch them from XML.
                var tList = typeof (List<>);
                if (propertyType.IsGenericType && tList.IsAssignableFrom(propertyType.GetGenericTypeDefinition()) ||
                    propertyType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == tList)) {
                    ReadXmlList(propertyValue, prop.Name, r);
                    continue;
                }

                if (typeof(DateTime?).IsAssignableFrom(propertyType)) {
                    // ReadElementContentAs won't accept a nullable DateTime.
                    propertyType = typeof(DateTime);
                }
                // ReSharper disable once AssignNullToNotNullAttribute
                prop.SetValue(this, r.ReadElementContentAs(propertyType, null), null);
            }
            r.ReadEndElement();
        }
开发者ID:CIR2000,项目名称:BusinessObjects,代码行数:45,代码来源:BusinessObject.cs

示例15: 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();
                }
            }
        }
开发者ID:tablesmit,项目名称:task-scheduler-managed-wrapper,代码行数:39,代码来源:XmlSerializationHelper.cs


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