本文整理汇总了C#中System.Xml.Linq.XName类的典型用法代码示例。如果您正苦于以下问题:C# XName类的具体用法?C# XName怎么用?C# XName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XName类属于System.Xml.Linq命名空间,在下文中一共展示了XName类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:mgulubov,项目名称:RestSharpHighQualityCodeTeamProject,代码行数:25,代码来源:XmlAttributeDeserializer.cs
示例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();
}
}
开发者ID:jradxl,项目名称:Generate-Database-Edmx-Automation,代码行数:31,代码来源:PropertyManager.cs
示例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;
}
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:7,代码来源:XmlUtility.cs
示例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;
}
开发者ID:40a,项目名称:PowerShell,代码行数:34,代码来源:Iso19770_2.cs
示例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);
}
开发者ID:arajar,项目名称:duality,代码行数:7,代码来源:ExtMethodsXml.cs
示例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);
}
开发者ID:arajar,项目名称:duality,代码行数:7,代码来源:ExtMethodsXml.cs
示例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;
}
开发者ID:pusp,项目名称:o2platform,代码行数:26,代码来源:FsmXObjects.cs
示例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;
}
开发者ID:pusp,项目名称:o2platform,代码行数:26,代码来源:FsmXObjects.cs
示例10: GenerateXElement
internal XElement GenerateXElement(XName name)
{
XNamespace xmlns = name.Namespace;
XElement element = new XElement(name);
return element;
}
开发者ID:onesimoh,项目名称:Andamio,代码行数:7,代码来源:Table.cs
示例11: GetElementValue
public static string GetElementValue(this XContainer elem, XName elementName)
{
XElement childElement = elem.Element(elementName);
if (childElement != null)
return childElement.Value;
return null;
}
开发者ID:Titaye,项目名称:SLExtensions,代码行数:7,代码来源:XElementExtensions.cs
示例12: GetAttribute
public static string GetAttribute(this XElement elem, XName attributeName)
{
XAttribute attribute = elem.Attribute(attributeName);
if (attribute != null)
return attribute.Value;
return null;
}
开发者ID:Titaye,项目名称:SLExtensions,代码行数:7,代码来源:XElementExtensions.cs
示例13: AttributeValue
internal static string AttributeValue(this XElement xml, XName attributeName)
{
var attribute = xml.Attribute(attributeName);
if (null == attribute)
return null;
return attribute.Value;
}
开发者ID:ahaadi,项目名称:markdown-scanner,代码行数:7,代码来源:ExtensionMethods.cs
示例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;
}
开发者ID:Korshunoved,项目名称:Win10reader,代码行数:7,代码来源:XmlExtensions.cs
示例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);
}
开发者ID:arajar,项目名称:duality,代码行数:7,代码来源:ExtMethodsXml.cs
示例16: XElement
public XElement this[XName section]
{
get
{
return root.Element(section) ?? new XElement(section);
}
}
开发者ID:kiinoo,项目名称:ILSpy,代码行数:7,代码来源:ToolSetSettings.cs
示例17: Element
public static XElement Element(this XContainer node, XName name, bool ignoreNamespace)
{
if (ignoreNamespace)
return node.Elements().FirstOrDefault(e => e.Name.LocalName == name.LocalName);
else
return node.Element(name);
}
开发者ID:arajar,项目名称:duality,代码行数:7,代码来源:ExtMethodsXml.cs
示例18: GetAttributeValue
public static string GetAttributeValue(this XElement element, XName name) {
XAttribute xAttribute = element.Attribute(name);
if (xAttribute != null) {
return xAttribute.Value;
}
return null;
}
开发者ID:aries544,项目名称:eXpand,代码行数:7,代码来源:StringExtensions.cs
示例19: GetAttribute
public static string GetAttribute(this XElement el, XName name, string defaultValue = "")
{
var attr = el.Attribute(name);
if (attr != null)
return attr.Value;
return defaultValue;
}
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:7,代码来源:_Extensions.cs
示例20: SerializeRoot
public XElement SerializeRoot(object obj, Type rootType, XName name, XSerializerNamespaceCollection namespaces, SerializationScope globalScope)
{
Debug.Assert(rootType.IsInstanceOfType(obj));
Debug.Assert(namespaces != null);
var root = SerializeXElement(obj, rootType, name, globalScope);
//导入命名空间。
foreach (var ns in namespaces)
root.SetAttributeValue(XNamespace.Xmlns + ns.Prefix, ns.Uri);
//处理导入的类型。
var nsCounter = 0;
foreach (var descendant in root.Descendants())
{
var actualTypeName = descendant.Annotation<XName>();
if (actualTypeName != null)
{
if (actualTypeName.Namespace == descendant.GetDefaultNamespace())
{
descendant.SetAttributeValue(SerializationHelper.Xsi + "type", actualTypeName.LocalName);
}
else
{
var prefix = descendant.GetPrefixOfNamespace(actualTypeName.Namespace);
if (prefix == null)
{
nsCounter++;
prefix = "nss" + nsCounter;
descendant.SetAttributeValue(XNamespace.Xmlns + prefix, actualTypeName.NamespaceName);
}
descendant.SetAttributeValue(SerializationHelper.Xsi + "type", prefix + ":" + actualTypeName.LocalName);
}
descendant.RemoveAnnotations<XName>();
}
}
return root;
}
开发者ID:CXuesong,项目名称:XSerializer,代码行数:35,代码来源:XSerializationState.cs
注:本文中的System.Xml.Linq.XName类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论