當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。