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


C# XPath.XPathResult类代码示例

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


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

示例1: WriteObject

		public bool WriteObject(XPathResult result, XPathNavigator node, object value)
		{
			var xml = new StringBuilder();
			var settings = new XmlWriterSettings
			{
				OmitXmlDeclaration = true,
				Indent = false
			};

			using (var writer = XmlWriter.Create(xml, settings))
			{
				if (value is IXmlSerializable)
				{
					SerializeCustom(writer, result, node, (IXmlSerializable)value);
				}
				else
				{
					Serialize(writer, result, node, value);
				}
				writer.Flush();
			}

			node.ReplaceSelf(xml.ToString());
			return true;
		}
开发者ID:Orvid,项目名称:NAntUniversalTasks,代码行数:25,代码来源:DefaultXmlSerializer.cs

示例2: WriteObject

		public bool WriteObject(XPathResult result, XPathNavigator node, object value)
		{
			var rootOverride = new XmlRootAttribute(node.LocalName)
			{
				Namespace = node.NamespaceURI
			};

			var xml = new StringBuilder();
			var settings = new XmlWriterSettings
			{
				OmitXmlDeclaration = true,
				Indent = false
			};
			var namespaces = new XmlSerializerNamespaces();
			namespaces.Add(string.Empty, string.Empty);
			if (string.IsNullOrEmpty(node.NamespaceURI) == false)
			{
				var prefix = result.Context.AddNamespace(node.NamespaceURI);
				namespaces.Add(prefix, node.NamespaceURI);
			}

			var serializer = new XmlSerializer(result.Type, rootOverride);

			using (var writer = XmlWriter.Create(xml, settings))
			{
				serializer.Serialize(writer, value, namespaces);
				writer.Flush();
			}

			node.ReplaceSelf(xml.ToString());

			return true;
		}
开发者ID:ThatExtraBit,项目名称:Castle.Core,代码行数:33,代码来源:DefaultXmlSerializer.cs

示例3: ReadObject

		public bool ReadObject(XPathResult result, XPathNavigator node, out object value)
		{
			using (var reader = node.ReadSubtree())
			{
				reader.MoveToContent();
				if (typeof(IXmlSerializable).IsAssignableFrom(result.Type))
				{
					value = DeserializeCustom(reader, result, node);
				}
				else
				{
					value = Deserialize(reader, result, node);
				}
			}

			return (value != null);
		}
开发者ID:Orvid,项目名称:NAntUniversalTasks,代码行数:17,代码来源:DefaultXmlSerializer.cs

示例4: Serialize

		private static void Serialize(XmlWriter writer, XPathResult result, XPathNavigator node, object value)
		{
			var namespaces = new XmlSerializerNamespaces();
			namespaces.Add(string.Empty, string.Empty);
			if (string.IsNullOrEmpty(node.NamespaceURI) == false)
			{
				var prefix = result.Context.AddNamespace(node.NamespaceURI);
				namespaces.Add(prefix, node.NamespaceURI);
			}

			var rootOverride = new XmlRootAttribute(node.LocalName)
			{
				Namespace = node.NamespaceURI
			};

			var serializer = new XmlSerializer(result.Type, rootOverride);
			serializer.Serialize(writer, value, namespaces);
		}
开发者ID:Orvid,项目名称:NAntUniversalTasks,代码行数:18,代码来源:DefaultXmlSerializer.cs

示例5: ReadObject

		public bool ReadObject(XPathResult result, XPathNavigator node, out object value)
		{
			var rootOverride = new XmlRootAttribute(node.LocalName)
			{
				Namespace = node.NamespaceURI
			};

			var serializer = new XmlSerializer(result.Type, rootOverride);

			using (var reader = node.ReadSubtree())
			{
				reader.MoveToContent();
				if (serializer.CanDeserialize(reader))
				{
					value = serializer.Deserialize(reader);
					return true;
				}				
			}

			value = null;
			return false;
		}
开发者ID:ThatExtraBit,项目名称:Castle.Core,代码行数:22,代码来源:DefaultXmlSerializer.cs

示例6: WriteCustom

		private bool WriteCustom(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
		{
			return result.WriteObject(value);
		}
开发者ID:Jarvin-Guan,项目名称:CleanAOP,代码行数:4,代码来源:XPathAdapter.cs

示例7: WriteArray

		private void WriteArray(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
		{
			var array = (Array)value;
			var itemType = array.GetType().GetElementType();

			foreach (var item in array)
			{
				var element = item;
				var node = result.CreateNode(itemType, element, type => dictionaryAdapter.GetXmlMeta(type));
				WriteProperty(node, ref element, dictionaryAdapter);
			}
		}
开发者ID:Jarvin-Guan,项目名称:CleanAOP,代码行数:12,代码来源:XPathAdapter.cs

示例8: WriteComponent

		private void WriteComponent(XPathResult result, ref object value, IDictionaryAdapter dictionaryAdapter)
		{
			var source = value as IDictionaryAdapter;
			if (source != null)
			{
				var sourceAdapter = For(source);
				if (sourceAdapter != null)
				{
					var sourceRoot = sourceAdapter.Root;
					var resultNode = result.GetNavigator(false);
					if (sourceRoot != null && resultNode != null && sourceRoot.IsSamePosition(resultNode))
						return;
				}

				var node = result.RemoveChildren();
				if (result.Type != source.Meta.Type && result.OmitPolymorphism == false)
				{
					var xmlType = source.GetXmlMeta().XmlType;
					var context = GetEffectiveContext(dictionaryAdapter);
					context.SetXmlType(xmlType.TypeName, xmlType.Namespace, node);
				}

				var element = (IDictionaryAdapter)ReadComponent(result, false, dictionaryAdapter);
				source.CopyTo(element);
				value = element;
			}
		}
开发者ID:Jarvin-Guan,项目名称:CleanAOP,代码行数:27,代码来源:XPathAdapter.cs

示例9: WriteFragment

		private void WriteFragment(XPathResult result, IXPathNavigable value)
		{
			var node = result.GetNavigator(true);
			if (node == null)
			{
				root.AppendChild(value.CreateNavigator());
			}
			else if (value != null)
			{
				node.ReplaceSelf(value.CreateNavigator());
			}
			else
			{
				node.DeleteSelf();
			}
		}
开发者ID:Jarvin-Guan,项目名称:CleanAOP,代码行数:16,代码来源:XPathAdapter.cs

示例10: ReadCustom

		private bool ReadCustom(XPathResult result, out object value)
		{
			return result.ReadObject(out value);
		}
开发者ID:Jarvin-Guan,项目名称:CleanAOP,代码行数:4,代码来源:XPathAdapter.cs

示例11: 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

示例12: WriteCollection

		private void WriteCollection(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
		{
			result.Remove();

			if (value != null)
			{
				if (result.Type.IsArray)
				{
					WriteArray(result, value, dictionaryAdapter);
				}
				else if (result.Type.IsGenericType)
				{
					WriteList(result, value, dictionaryAdapter);
				}
			}
		}
开发者ID:ewhauser,项目名称:Castle.Core,代码行数:16,代码来源:XPathAdapter.cs

示例13: WriteComponent

		private void WriteComponent(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
		{
			if (result.Property != null)
			{
				dictionaryAdapter.This.ExtendedProperties.Remove(result.Property.PropertyName);
			}

			if (value == null)
			{
				result.Remove();
				return;
			}

			var source = value as IDictionaryAdapter;
			if (source != null)
			{
				var node = result.RemoveChildren();
				if (result.Type != source.Meta.Type && result.OmitPolymorphism == false)
				{
					var xmlType = source.GetXmlMeta().XmlType;
					Context.SetXmlType(xmlType.TypeName, xmlType.Namespace, node);
				}
				var element = (IDictionaryAdapter)ReadComponent(result, false, dictionaryAdapter);
				source.CopyTo(element);
			}
		}
开发者ID:ewhauser,项目名称:Castle.Core,代码行数:26,代码来源:XPathAdapter.cs

示例14: WriteSimple

		private void WriteSimple(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
		{
			if (value == null)
			{
				result.Remove();
				if (result.Property != null)
					dictionaryAdapter.This.ExtendedProperties.Remove(result.Property.PropertyName);
				return;
			}

			var node = result.GetNavigator(true);

			if (result.Type.IsEnum || result.Type == typeof(Guid))
			{
				node.SetTypedValue(value.ToString());
			}
			else
			{
				try
				{
					node.SetTypedValue(value);
				}
				catch (InvalidCastException)
				{
					if (DefaultXmlSerializer.Instance.WriteObject(result, node, value) && result.Property != null)
					{
						dictionaryAdapter.This.ExtendedProperties[result.Property.PropertyName] = value;
					}
				}
			}
		}
开发者ID:ewhauser,项目名称:Castle.Core,代码行数:31,代码来源:XPathAdapter.cs

示例15: WriteProperty

		private void WriteProperty(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
		{
			var propertyType = result.Type;

			if (WriteCustom(result, value, dictionaryAdapter))
				return;

			if (propertyType == typeof(string))
			{
				WriteSimple(result, value, dictionaryAdapter);
			}
			else if (typeof(IXPathNavigable).IsAssignableFrom(propertyType))
			{
				WriteFragment(result, (IXPathNavigable)value);
			}
			else if (propertyType.IsArray || typeof(IEnumerable).IsAssignableFrom(propertyType))
			{
				WriteCollection(result, value, dictionaryAdapter);
			}
			else if (propertyType.IsInterface)
			{
				WriteComponent(result, value, dictionaryAdapter);
			}
			else
			{
				WriteSimple(result, value, dictionaryAdapter);
			}
		}
开发者ID:ewhauser,项目名称:Castle.Core,代码行数:28,代码来源:XPathAdapter.cs


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