本文整理汇总了C#中System.Xml.Linq.XName类的典型用法代码示例。如果您正苦于以下问题:C# XName类的具体用法?C# XName怎么用?C# XName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XName类属于System.Xml.Linq命名空间,在下文中一共展示了XName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValueFromXml
protected override object GetValueFromXml(XElement root, XName name, PropertyInfo prop)
{
var isAttribute = false;
// Check for the DeserializeAs attribute on the property
var options = prop.GetAttribute<DeserializeAsAttribute>();
if (options != null)
{
name = options.Name ?? name;
isAttribute = options.Attribute;
}
if (isAttribute)
{
var attributeVal = GetAttributeByName(root, name);
if (attributeVal != null)
{
return attributeVal.Value;
}
}
return base.GetValueFromXml(root, name, prop);
}
示例2: PropertyManager
/// <summary>
/// Initializes a new instance of the <see cref="PropertyManager"/> class.
/// </summary>
public PropertyManager(string schema)
{
keyElementName = XName.Get("Key", schema);
entityTypeName = XName.Get(entityTypeNameString, schema);
entityContainerName = XName.Get("EntityContainer", schema);
entitySetName = XName.Get("EntitySet", schema);
}
开发者ID:mlzharov,项目名称:Asp.Net-Identity-Tools-for-Entity-Framework-model,代码行数:10,代码来源:PropertyManager.cs
示例3: SetValue
public static void SetValue(XElement _parent, PropertyExtensionContext _context, XName xName, bool value)
{
bool propertyValue = value;
// Make changes to the .edmx document in an EntityDesignerChangeScope to enable undo/redo of changes.
using (EntityDesignerChangeScope scope = _context.CreateChangeScope("Set EDMXFileTools"))
{
if (_parent.HasElements)
{
XElement lastChild = _parent.Elements().Where<XElement>(element => element != null && element.Name == xName).LastOrDefault();
if (lastChild != null)
{
// Property element already exists under the EntityType element, so update its value.
lastChild.SetValue(propertyValue.ToString());
}
else
{
// Property element does not exist, so create a new one as the last child of the EntityType element.
_parent.Elements().Last().AddAfterSelf(new XElement(xName, propertyValue.ToString()));
}
}
else
{
// The element has no child elements so create a new MyNewProperty element as its first child.
_parent.Add(new XElement(xName, propertyValue.ToString()));
}
// Commit the changes.
scope.Complete();
}
}
示例4: CreateDocument
private static XDocument CreateDocument(XName rootName, IFileSystem fileSystem, string path)
{
XDocument document = new XDocument(new XElement(rootName));
// Add it to the file system
fileSystem.AddFile(path, document.Save);
return document;
}
示例5: AddAttribute
/// <summary>
/// Adds a new attribute to the element
/// Does not permit modification of an existing attribute.
/// Does not add empty or null attributes or values.
/// </summary>
/// <param name="element">The element to add the attribute to</param>
/// <param name="attribute">The attribute to add</param>
/// <param name="value">the value of the attribute to add</param>
/// <returns>The element passed in. (Permits fluent usage)</returns>
internal static XElement AddAttribute(this XElement element, XName attribute, string value) {
if (element == null) {
return null;
}
// we quietly ignore attempts to add empty data or attributes.
if (string.IsNullOrWhiteSpace(value) || attribute == null || string.IsNullOrWhiteSpace(attribute.ToString())) {
return element;
}
// Swidtag attributes can be added but not changed -- if it already exists, that's not permitted.
var current = element.GetAttribute(attribute);
if (!string.IsNullOrWhiteSpace(current)) {
if (value != current) {
throw new Exception("Attempt to change Attribute '{0}' present in element '{1}'".format(attribute.LocalName, element.Name.LocalName));
}
// if the value was set to that already, don't worry about it.
return element;
}
element.SetAttributeValue(attribute, value);
return element;
}
示例6: Ancestors
public static IEnumerable<XElement> Ancestors(this XNode node, XName name, bool ignoreNamespace)
{
if (ignoreNamespace)
return node.Ancestors().Where(e => e.Name.LocalName == name.LocalName);
else
return node.Ancestors(name);
}
示例7: ElementsAfterSelf
public static IEnumerable<XElement> ElementsAfterSelf(this XContainer node, XName name, bool ignoreNamespace)
{
if (ignoreNamespace)
return node.ElementsAfterSelf().Where(e => e.Name.LocalName == name.LocalName);
else
return node.ElementsAfterSelf(name);
}
示例8: ExecuteFSMSubGroup
internal XElement ExecuteFSMSubGroup(IEnumerator<XElement> enumerator, XName[] namesInList) {
Debug.Assert(namesInList != null);
XElement currElem = null;
WildCard matchingWildCard = null;
XName matchingName = null;
while(enumerator.MoveNext()){
currElem = enumerator.Current;
currentState = FsmMakeTransition(currentState, currElem.Name, out matchingName, out matchingWildCard);
if (currentState!= FSM.InvalidState) {
if ( matchingName != null)
for(int i =0; i < namesInList.Length; i++) {
if (namesInList.GetValue(i).Equals(currElem.Name)) return currElem;
}
}
else {//Get stuck. No recovery attempt is provided for now.
return null;
}
}
//No matching elements/wildcards are found
return null;
}
示例9: ExecuteFSM
internal XElement ExecuteFSM(IEnumerator<XElement> enumerator, XName requestingXName, WildCard requestingWildCard) {
XElement currElem = null;
WildCard matchingWildCard = null;
XName matchingName = null;
while(enumerator.MoveNext()){
currElem = enumerator.Current;
currentState = FsmMakeTransition(currentState, currElem.Name, out matchingName, out matchingWildCard);
if (currentState!= FSM.InvalidState) {
if ( (requestingXName != null) && (matchingName != null)) {
if (requestingXName.Equals(currElem.Name)) return currElem;
}
else if ( (requestingWildCard != null) && (matchingWildCard != null) ){//requesting for ANY
if (requestingWildCard.Allows(currElem.Name)) //Make sure current element is allowed by requesting ANY property
return currElem;
}
}
else {//Get stuck. No recovery attempt is provided for now.
return null;
}
}
//No matching elements/wildcards are found
return null;
}
示例10: GenerateXElement
internal XElement GenerateXElement(XName name)
{
XNamespace xmlns = name.Namespace;
XElement element = new XElement(name);
return element;
}
示例11: GetElementValue
public static string GetElementValue(this XContainer elem, XName elementName)
{
XElement childElement = elem.Element(elementName);
if (childElement != null)
return childElement.Value;
return null;
}
示例12: GetAttribute
public static string GetAttribute(this XElement elem, XName attributeName)
{
XAttribute attribute = elem.Attribute(attributeName);
if (attribute != null)
return attribute.Value;
return null;
}
示例13: AttributeValue
internal static string AttributeValue(this XElement xml, XName attributeName)
{
var attribute = xml.Attribute(attributeName);
if (null == attribute)
return null;
return attribute.Value;
}
示例14: GetStringAttribute
public static string GetStringAttribute(this XElement element, XName name)
{
XAttribute xattribute = element.Attribute(name);
if (xattribute != null)
return xattribute.Value;
return string.Empty;
}
示例15: Descendants
public static IEnumerable<XElement> Descendants(this XContainer container, XName name, bool ignoreNamespace)
{
if (ignoreNamespace)
return container.Descendants().Where(e => e.Name.LocalName == name.LocalName);
else
return container.Descendants(name);
}