本文整理汇总了C#中IDictionaryAdapter.GetXmlMeta方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionaryAdapter.GetXmlMeta方法的具体用法?C# IDictionaryAdapter.GetXmlMeta怎么用?C# IDictionaryAdapter.GetXmlMeta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionaryAdapter
的用法示例。
在下文中一共展示了IDictionaryAdapter.GetXmlMeta方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvalidOperationException
void IDictionaryInitializer.Initialize(IDictionaryAdapter dictionaryAdapter, object[] behaviors)
{
var meta = dictionaryAdapter.Meta;
if (meta.MetaInitializers.OfType<XPathBehavior>().FirstOrDefault() == null)
{
throw new InvalidOperationException(string.Format(
"Interface {0} requested xpath support, but was not configured properly. " +
"Did you forget to add an XPathBehavior?", meta.Type.FullName));
}
var xmlMeta = dictionaryAdapter.GetXmlMeta();
if (dictionaryAdapter.This.CreateStrategy == null)
{
dictionaryAdapter.This.CreateStrategy = this;
dictionaryAdapter.This.AddCopyStrategy(this);
}
if (rootXmlMeta == null)
{
rootXmlMeta = xmlMeta;
Context.ApplyBehaviors(rootXmlMeta, behaviors);
if (Parent == null)
{
foreach (var behavior in behaviors)
{
if (behavior is XPathAttribute)
{
var attrib = (XPathAttribute)behavior;
var compiledExpression = attrib.CompiledExpression;
if (MoveOffRoot(root, XPathNodeType.Element) == false || Context.Matches(compiledExpression, root))
{
break;
}
var navigator = Context.SelectSingleNode(compiledExpression, root);
if (navigator != null)
{
root = navigator;
break;
}
}
}
MoveOffRoot(root, XPathNodeType.Element);
}
}
else
{
if (overlays == null)
overlays = new Dictionary<Type, XPathContext>();
XPathContext overlay;
if (overlays.TryGetValue(meta.Type, out overlay) == false)
{
overlay = new XPathContext().ApplyBehaviors(xmlMeta, behaviors);
overlays.Add(meta.Type, overlay);
}
}
}
示例2: InvalidOperationException
void IDictionaryInitializer.Initialize(IDictionaryAdapter dictionaryAdapter, object[] behaviors)
{
var meta = dictionaryAdapter.Meta;
if (meta.MetaInitializers.OfType<XPathBehavior>().FirstOrDefault() == null)
{
throw new InvalidOperationException(string.Format(
"Interface {0} requested xpath support, but was not configured properly. " +
"Did you forget to add an XPathBehavior?", meta.Type.FullName));
}
dictionaryAdapter.This.CreateStrategy = this;
Context.ApplyBehaviors(behaviors);
xmlMeta = dictionaryAdapter.GetXmlMeta();
if (string.IsNullOrEmpty(xmlMeta.XmlType.Namespace) == false)
{
Context.AddNamespace(string.Empty, xmlMeta.XmlType.Namespace);
}
if (Parent == null)
{
foreach (var behavior in behaviors)
{
if (behavior is XPathAttribute)
{
var attrib = (XPathAttribute)behavior;
var compiledExpression = attrib.CompiledExpression;
if (MoveOffRoot(root, XPathNodeType.Element) == false || Context.Matches(compiledExpression, root))
{
break;
}
var navigator = Context.SelectSingleNode(compiledExpression, root);
if (navigator != null)
{
root = navigator;
break;
}
}
}
MoveOffRoot(root, XPathNodeType.Element);
}
}
示例3: EvaluateProperty
private XPathResult EvaluateProperty(string key, PropertyDescriptor property, IDictionaryAdapter dictionaryAdapter)
{
object result;
XPathExpression xpath = null;
object matchingBehavior = null;
Func<XPathNavigator> create = null;
var context = GetEffectiveContext(dictionaryAdapter);
var xmlMeta = dictionaryAdapter.GetXmlMeta(property.Property.DeclaringType);
var keyContext = context.CreateChild(xmlMeta, property.Behaviors);
foreach (var behavior in property.Behaviors)
{
string name = key, ns = null;
Func<XPathNavigator> matchingCreate = null;
if (behavior is XmlElementAttribute)
{
xpath = XPathElement;
var attrib = (XmlElementAttribute)behavior;
if (string.IsNullOrEmpty(attrib.ElementName) == false)
name = attrib.ElementName;
if (string.IsNullOrEmpty(attrib.Namespace) == false)
ns = attrib.Namespace;
matchingCreate = () => keyContext.AppendElement(name, ns, root.Clone());
}
else if (behavior is XmlAttributeAttribute)
{
xpath = XPathAttribute;
var attrib = (XmlAttributeAttribute)behavior;
if (string.IsNullOrEmpty(attrib.AttributeName) == false)
name = attrib.AttributeName;
if (string.IsNullOrEmpty(attrib.Namespace) == false)
ns = attrib.Namespace;
matchingCreate = () => keyContext.CreateAttribute(name, ns, root.Clone());
}
else if (behavior is XmlArrayAttribute)
{
xpath = XPathElement;
var attrib = (XmlArrayAttribute)behavior;
if (string.IsNullOrEmpty(attrib.ElementName) == false)
name = attrib.ElementName;
if (string.IsNullOrEmpty(attrib.Namespace) == false)
ns = attrib.Namespace;
matchingCreate = () => keyContext.AppendElement(name, ns, root.Clone());
}
else if (behavior is XPathAttribute)
{
var attrib = (XPathAttribute)behavior;
xpath = attrib.CompiledExpression;
}
else
{
continue;
}
if (xpath != null)
{
keyContext.Arguments.Clear();
keyContext.Arguments.AddParam("key", "", name);
keyContext.Arguments.AddParam("ns", "", ns ?? XPathContext.IgnoreNamespace);
if (keyContext.Evaluate(xpath, Root, out result))
{
create = matchingCreate ?? create;
return new XPathResult(property, key, result, keyContext, behavior, create);
}
}
matchingBehavior = matchingBehavior ?? behavior;
create = create ?? matchingCreate;
}
if (xpath != null)
return new XPathResult(property, key, null, keyContext, matchingBehavior, create);
keyContext.Arguments.Clear();
keyContext.Arguments.AddParam("key", "", key);
keyContext.Arguments.AddParam("ns", "", XPathContext.IgnoreNamespace);
create = create ?? (() => keyContext.AppendElement(key, null, root));
keyContext.Evaluate(XPathElementOrAttribute, Root, out result);
return new XPathResult(property, key, result, keyContext, null, create);
}
示例4: WriteList
private void WriteList(XPathResult result, object value, IDictionaryAdapter dictionaryAdapter)
{
var arguments = result.Type.GetGenericArguments();
var itemType = arguments[0];
foreach (var item in (IEnumerable)value)
{
var element = item;
var node = result.CreateNode(itemType, element, type => dictionaryAdapter.GetXmlMeta(type));
WriteProperty(node, ref element, dictionaryAdapter);
}
}
示例5: 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);
}
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}