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


C# XPathResult.GetNodes方法代码示例

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


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

示例1: ReadList

		private object ReadList(XPathResult result, IDictionaryAdapter dictionaryAdapter)
		{
			Type listType = null, initializerType = null;
			var arguments = result.Type.GetGenericArguments();
			var genericDef = result.Type.GetGenericTypeDefinition();
			var itemType = arguments[0];

			Func<Type, XmlMetadata> getXmlMeta = type => dictionaryAdapter.GetXmlMeta(type);
			var itemNodes = result.GetNodes(itemType, getXmlMeta);
			if (itemNodes == null) return null;

			if (genericDef == typeof(IEnumerable<>) || genericDef == typeof(ICollection<>) || genericDef == typeof(List<>))
			{
				listType = typeof(EditableList<>).MakeGenericType(arguments);
			}
			else if (
#if !DOTNET35
				//NOTE: what about SortedSet?
				genericDef == typeof(ISet<>) || 
#endif
				genericDef == typeof(HashSet<>))
			{
				listType = typeof(List<>).MakeGenericType(arguments);
			}
			else
			{
				listType = typeof(EditableBindingList<>).MakeGenericType(arguments);
				initializerType = typeof(BindingListInitializer<>).MakeGenericType(arguments);
			}
			
			var list = (IList)Activator.CreateInstance(listType);

			foreach (var item in itemNodes)
			{
				list.Add(ReadProperty(item, false, dictionaryAdapter));
			}

			if (
#if !DOTNET35
				//NOTE: what about SortedSet?
				genericDef == typeof(ISet<>) ||
#endif
				genericDef == typeof(HashSet<>))
			{
				return Activator.CreateInstance(typeof(HashSet<>).MakeGenericType(arguments), list);
			}

			if (initializerType != null)
			{
				Func<object> addNew = () =>
				{
					var node = result.CreateNode(itemType, null, getXmlMeta);
					return ReadProperty(node, false, dictionaryAdapter);
				};

				Func<int, object, object> addAt = (index, item) =>
				{
					var node = result.CreateNode(itemType, item, getXmlMeta);
					WriteProperty(node, ref item, dictionaryAdapter);
					return item;
				};

				Func<int, object, object> setAt = (index, item) =>
				{
					var node = result.GetNodeAt(itemType, index);
					WriteProperty(node, ref item, dictionaryAdapter);
					return item;
				};

				Action<int> removeAt = index =>
				{
					object value = list;
					if (dictionaryAdapter.ShouldClearProperty(result.Property, value))
					{
						result.Remove(true);
						return;
					}
					result.RemoveAt(index);
				};

				Action reset = () =>
				{
					object value = list;
					if (dictionaryAdapter.ShouldClearProperty(result.Property, value))
					{
						result.Remove(true);
						return;
					}
					WriteCollection(result, ref value, dictionaryAdapter);
				};

				var initializer = (IValueInitializer)Activator.CreateInstance(
					initializerType, addAt, addNew, setAt, removeAt, reset);
				initializer.Initialize(dictionaryAdapter, list);
			}

			return list;
		}
开发者ID:Jarvin-Guan,项目名称:CleanAOP,代码行数:98,代码来源:XPathAdapter.cs

示例2: ReadArray

		private object ReadArray(XPathResult result, IDictionaryAdapter dictionaryAdapter)
		{
			var itemType = result.Type.GetElementType();
			var itemNodes = result.GetNodes(itemType, type => dictionaryAdapter.GetXmlMeta(type));
			if (itemNodes == null) return null;
			var items = itemNodes.Select(node => ReadProperty(node, false, dictionaryAdapter)).ToArray();
			var array = Array.CreateInstance(itemType, items.Length);
			items.CopyTo(array, 0);
			return array;
		}
开发者ID:AndreKraemer,项目名称:Castle.Core,代码行数:10,代码来源:XPathAdapter.cs

示例3: ReadArray

		private object ReadArray(XPathResult result, IDictionaryAdapter dictionaryAdapter)
		{
			if (result.Type == typeof(byte[]))
			{
				XPathNavigator node;
				if (result.GetNavigator(false, true, out node) && node != null)
				{
					return Convert.FromBase64String(node.InnerXml);
				}
				return null;
			}
			var itemType = result.Type.GetElementType();
			var itemNodes = result.GetNodes(itemType, type => dictionaryAdapter.GetXmlMeta(type));
			if (itemNodes == null) return null;
			var items = itemNodes.Select(node => ReadProperty(node, false, dictionaryAdapter)).ToArray();
			var array = Array.CreateInstance(itemType, items.Length);
			items.CopyTo(array, 0);
			return array;
		}
开发者ID:Jarvin-Guan,项目名称:CleanAOP,代码行数:19,代码来源:XPathAdapter.cs

示例4: ReadList

		private object ReadList(XPathResult result, IDictionaryAdapter dictionaryAdapter)
		{
			Type listType = null, initializerType = null;
			var arguments = result.Type.GetGenericArguments();
			var genericDef = result.Type.GetGenericTypeDefinition();
			var itemType = arguments[0];

			if (genericDef == typeof(List<>))
			{
				listType = typeof(EditableList<>).MakeGenericType(arguments);
			}
			else
			{
				listType = typeof(EditableBindingList<>).MakeGenericType(arguments);
				initializerType = typeof(BindingListInitializer<>).MakeGenericType(arguments);
			}
			
			var list = (IList)Activator.CreateInstance(listType);
			Func<Type, XmlMetadata> getXmlMeta = type => dictionaryAdapter.GetXmlMeta(type);

			foreach (var item in result.GetNodes(itemType, getXmlMeta))
			{
				list.Add(ReadProperty(item, false, dictionaryAdapter));
			}

			if (initializerType != null)
			{
				Func<object> addNew = () =>
				{
					var node = result.CreateNode(itemType, null, getXmlMeta);
					return ReadProperty(node, false, dictionaryAdapter);
				};

				Action<int, object> addAt = (index, item) =>
				{
					var node = result.CreateNode(itemType, item, getXmlMeta);
					WriteProperty(node, item, dictionaryAdapter);
				};

				Action<int, object> setAt = (index, item) =>
				{
					var node = result.GetNodeAt(itemType, index);
					WriteProperty(node, item, dictionaryAdapter);
				};

				Action<int> removeAt = index => result.RemoveAt(index);

				var initializer = (IValueInitializer)Activator.CreateInstance(
					initializerType, addAt, addNew, setAt, removeAt);
				initializer.Initialize(dictionaryAdapter, list);
			}

			return list;
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:54,代码来源:XPathAdapter.cs


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