本文整理汇总了C#中System.Xml.XPath.XPathResult.GetNavigator方法的典型用法代码示例。如果您正苦于以下问题:C# XPathResult.GetNavigator方法的具体用法?C# XPathResult.GetNavigator怎么用?C# XPathResult.GetNavigator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathResult
的用法示例。
在下文中一共展示了XPathResult.GetNavigator方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteCollection
private void WriteCollection(XPathResult result, ref object value, IDictionaryAdapter dictionaryAdapter)
{
if (value is byte[])
{
var node = result.GetNavigator(true);
node.SetValue(Convert.ToBase64String((byte[])value));
return;
}
result.Remove(value == null);
if (value != null)
{
if (result.Type.IsArray)
{
WriteArray(result, value, dictionaryAdapter);
}
else if (result.Type.IsGenericType)
{
WriteList(result, value, dictionaryAdapter);
}
if (result.Property != null)
{
value = ((IDictionaryPropertyGetter)this).GetPropertyValue(dictionaryAdapter, result.Key, null, result.Property, false);
}
}
}
示例2: WriteSimple
private void WriteSimple(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
{
var node = result.GetNavigator(true);
if (result.Type.IsEnum || result.Type == typeof(Guid))
{
node.SetTypedValue(value.ToString());
}
else
{
try
{
node.SetTypedValue(value);
}
catch (InvalidCastException)
{
DefaultXmlSerializer.Instance.WriteObject(result, node, value);
}
}
}
示例3: 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;
}
}
示例4: 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;
}
示例5: 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();
}
}
示例6: ReadSimple
private object ReadSimple(XPathResult result)
{
XPathNavigator node;
if (result.GetNavigator(false, true, out node))
{
if (node != null)
{
Type underlyingType;
if (IsNullableType(result.Type, out underlyingType) == false)
{
underlyingType = result.Type;
}
if (underlyingType.IsEnum)
{
return Enum.Parse(underlyingType, node.Value);
}
else if (underlyingType == typeof(Guid))
{
return new Guid(node.Value);
}
try
{
return node.ValueAs(underlyingType);
}
catch (InvalidCastException)
{
object value;
if (DefaultXmlSerializer.Instance.ReadObject(result, node, out value))
return value;
}
}
if (result.Result != null)
return Convert.ChangeType(result.Result, result.Type);
}
return null;
}
示例7: ReadComponent
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter)
{
XPathNavigator source;
if (result.Property != null)
ifExists = ifExists || dictionaryAdapter.Meta.Type.IsAssignableFrom(result.Property.PropertyType);
if (result.GetNavigator(false, true, out source) == false || (source == null && ifExists))
{
return null;
}
XPathAdapter xpathAdapter;
var elementType = result.Type;
if (source != null)
{
if (result.XmlMeta != null)
{
elementType = result.XmlMeta.Type;
}
else
{
var xmlType = GetEffectiveContext(dictionaryAdapter).GetXmlType(source);
elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType;
}
xpathAdapter = new XPathAdapter(source, this);
}
else
{
Func<XPathNavigator> createSource = () => result.GetNavigator(true);
xpathAdapter = new XPathAdapter(createSource, this);
}
return Create(dictionaryAdapter, elementType, null, xpathAdapter);
}
示例8: 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;
}
}
}
}
示例9: ReadFragment
private object ReadFragment(XPathResult result)
{
XPathNavigator node;
result.GetNavigator(false, true, out node);
if (node == null) return null;
if (result.Type == typeof(XmlElement))
{
var document = new XmlDocument();
document.Load(node.ReadSubtree());
return document.DocumentElement;
}
return node.Clone();
}
示例10: ReadComponent
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter)
{
XPathAdapter xpathAdapter;
var source = result.GetNavigator(false);
if (source == null && ifExists) return null;
var elementType = result.Type;
if (source != null)
{
if (result.XmlMeta != null)
{
elementType = result.XmlMeta.Type;
}
else
{
var xmlType = Context.GetXmlType(source);
elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType;
}
xpathAdapter = new XPathAdapter(source, this);
}
else
{
Func<XPathNavigator> createSource = () => result.GetNavigator(true);
xpathAdapter = new XPathAdapter(createSource, this);
}
var component = Create(dictionaryAdapter, elementType, null, xpathAdapter);
if (result.Property != null)
dictionaryAdapter.This.ExtendedProperties[result.Property.PropertyName] = component;
return component;
}
示例11: WritePrimitive
private void WritePrimitive(XPathResult result, object value)
{
if (value == null)
{
result.Remove();
}
else if (result.Type.IsEnum)
{
result.GetNavigator(true).SetTypedValue(value.ToString());
}
else
{
try
{
result.GetNavigator(true).SetTypedValue(value);
}
catch (InvalidCastException)
{
var converter = TypeDescriptor.GetConverter(result.Type);
if (converter != null && converter.CanConvertTo(typeof(string)))
{
value = converter.ConvertToString(value);
result.GetNavigator(true).SetTypedValue(value);
}
}
}
}
示例12: ReadComponent
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter)
{
XPathAdapter adapter;
Func<XPathNavigator> createSource = null;
var source = result.GetNavigator(false);
if (source == null && ifExists) return null;
var elementType = result.Type;
if (source != null)
{
if (result.XmlMeta != null)
{
elementType = result.XmlMeta.Type;
}
else
{
var xmlType = context.GetXmlType(source);
elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType;
}
adapter = new XPathAdapter(source, this);
}
else
{
if (createSource == null)
{
createSource = () => result.GetNavigator(true);
}
adapter = new XPathAdapter(createSource, this);
}
var component = dictionaryAdapter.This.Factory.GetAdapter(elementType, new Hashtable(),
new DictionaryDescriptor().AddBehavior(XPathBehavior.Instance, adapter));
if (result.Property != null)
{
dictionaryAdapter.This.ExtendedProperties[result.Property.PropertyName] = component;
}
return component;
}
示例13: ReadPrimitive
private object ReadPrimitive(XPathResult result)
{
var node = result.GetNavigator(false);
if (node != null)
{
if (result.Type.IsEnum)
{
return Enum.Parse(result.Type, node.Value);
}
try
{
return node.ValueAs(result.Type);
}
catch (InvalidCastException)
{
var converter = TypeDescriptor.GetConverter(result.Type);
if (converter != null && converter.CanConvertFrom(typeof(string)))
{
return converter.ConvertFromString(node.Value);
}
}
}
if (result.Result != null)
{
return Convert.ChangeType(result.Result, result.Type);
}
return null;
}
示例14: ReadSimple
private object ReadSimple(XPathResult result)
{
var node = result.GetNavigator(false);
if (node != null)
{
if (result.Type.IsEnum)
return Enum.Parse(result.Type, node.Value);
try
{
return node.ValueAs(result.Type);
}
catch (InvalidCastException)
{
object value;
if (DefaultXmlSerializer.Instance.ReadObject(result, node, out value))
return value;
}
}
if (result.Result != null)
return Convert.ChangeType(result.Result, result.Type);
return null;
}