本文整理汇总了C#中this.Attribute方法的典型用法代码示例。如果您正苦于以下问题:C# this.Attribute方法的具体用法?C# this.Attribute怎么用?C# this.Attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAttr
public static string GetAttr(this XElement el, string name)
{
if (el.Attribute(name) == null)
return null;
else
return el.Attribute(name).Value;
}
示例2: ToBsonDocument
public static BsonDocument ToBsonDocument(this XElement xElement)
{
var bsonDocument = new BsonDocument();
var type = xElement.Name.ToString();
bsonDocument.Add(Constants._TYPE, type);
var mainId = xElement.Attribute(Constants._ID) != null ? xElement.Attribute(Constants._ID).Value : null;
foreach (XAttribute attribure in xElement.Attributes())
{
var key = attribure.Name.ToString();
var value = attribure.Value;
if (bsonDocument.Contains(key))
bsonDocument.Set(key, value);
else
bsonDocument.Add(key, value);
}
foreach (XElement kid in xElement.Descendants())
{
var id = kid.Attribute(Constants._ID);
if (id == null || mainId == null)
{
bsonDocument.Add(kid.Name.ToString(), kid.ToBsonDocument());
}
else
{
kid.SetAttributeValue(Constants.PARENT_ID, mainId);
DBFactory.GetData().Save(kid);
}
}
return bsonDocument;
}
示例3: UpdateXElement
internal static void UpdateXElement(this XElement element, SettingsInfo settings, XNamespace ns)
{
element.Attribute("ID").Value = settings.Id.ToString();
element.Attribute("processorRef").Value = settings.Processor.Id.ToString();
element.Element(ns + "name").Value = settings.Name;
element.Element(ns + "serialPortSettings").UpdateXElement(settings.SerialPortSettings, ns);
}
示例4: ParseSeatGroup
static SeatGroup ParseSeatGroup(this XElement cell)
{
return new HtmlSeatGroup(
(string)cell.Attribute("data-person"),
(int)cell.Attribute("data-count")
);
}
示例5: GetColor
public static Color GetColor(this XElement element, string name, string defaultColor) {
return
ColorReflector.ToColorFromHex(element.Attribute(name) != null
? element.Attribute(name).Value
: element.Attribute(defaultColor).Value);
//return (Color) ColorConverter.ConvertFromString(element.Attribute(name).Value);
}
示例6: GetNullColor
public static Color? GetNullColor(this XElement element, string name)
{
return element.Attribute(name) != null
? ColorReflector.ToColorFromHex(element.Attribute(name).Value)
: new Color?();
//return (Color) ColorConverter.ConvertFromString(element.Attribute(name).Value);
}
示例7: GetAttribute
public static string GetAttribute(this XElement element, string attributeName)
{
if (!element.HasAttributes ||
element.Attribute(attributeName) == null ||
string.IsNullOrEmpty(element.Attribute(attributeName).Value))
return string.Empty;
return element.Attribute(attributeName).Value;
}
示例8: GetPortalSetting
public static PortalSettings GetPortalSetting(this XElement element, string id)
{
var portalItem = new PortalSettings();
portalItem.AlwaysShowEditButton = Convert.ToBoolean(element.Attribute("AlwaysShowEditButton").Value);
portalItem.PortalName = element.Attribute("PortalName").Value;
portalItem.PortalId = id;
return portalItem;
}
示例9: GenerateXPathFromXElement
public static string GenerateXPathFromXElement(this XElement xUi)
{
var original = xUi.GetAttributeValue("XPath");
if (!String.IsNullOrEmpty(original))
return original;
var tag = "//*";
var xTag = xUi.Attribute("tag");
var xType = xUi.Attribute("type");
if (xType != null)
{
if (xType.Value.Equals("a"))
{
tag = "//a";
xType.Remove();
}
if(xType.Value.Equals("table")||xType.Value.Equals("div"))
{
var textAttr = xUi.Attribute("text");
if(textAttr!=null) textAttr.Remove();
}
}
if (xTag != null)
{
tag = "//" + xTag.Value;
xTag.Remove();
}
var xpath = tag;
if (xUi.Attributes().Any())
{
xpath = xpath + "[";
var count = 0;
foreach (XAttribute xa in xUi.Attributes())
{
var key = xa.Name.ToString();
if (key.StartsWith("_"))
continue;
var value = xa.Value;
if (count > 0)
xpath = xpath + " and ";
if (key.Equals("text"))
{
if (value.Length < 32)
xpath = xpath + key + "()='" + value + "' ";
else
{
xpath = xpath + "contains(text(),'" + value.Substring(0, 16) + "') ";
}
}
else
xpath = xpath + "@" + key + "='" + value + "' ";
count++;
}
xpath = xpath + "]";
}
return xpath;
}
示例10: ToProcessor
internal static Processor ToProcessor(this XElement element, XNamespace ns)
{
return new Processor(Convert.ToInt32(element.Attribute("ID").Value, 10),
element.Attribute("Name").Value,
Convert.ToInt32(element.Element(ns + "eepromSize").Value, 16),
Convert.ToInt32(element.Element(ns + "flashSize").Value, 16),
Convert.ToInt32(element.Element(ns + "bootStartAddress").Value, 16),
Convert.ToInt32(element.Element(ns + "bootEndAddress").Value, 16));
}
示例11: ToField
public static Field ToField(this XElement f)
{
if (f.Name != Constants.Field)
{
throw new ArgumentException("Invalid argument.", "f");
}
return new Field(f.Attribute(Constants.Name).Value, f.Attribute(Constants.Required).Value == Constants.True);
}
示例12: ParseXYZ
public static Vector3 ParseXYZ(this XElement element, Vector3 defaultValue)
{
return new Vector3
(
element.Attribute("x").ToFloat(defaultValue.x),
element.Attribute("y").ToFloat(defaultValue.y),
element.Attribute("z").ToFloat(defaultValue.z)
);
}
示例13: IsNullOrNullContract
/// <summary>
/// Returns true if this XElement is null, or an obix:Null contract.
/// </summary>
/// <returns>true if this XElement is null or a null contract, false otherwise.</returns>
public static bool IsNullOrNullContract(this XElement element) {
if (element == null) {
return true;
}
return element.HasAttributes
&& element.Attribute("null") != null
&& element.Attribute("null").Value == "true";
}
示例14: GetValue
public static string GetValue(this XElement self, string attributeName, bool toLower = true)
{
if (self.Attribute(attributeName) == null)
return null;
return toLower ?
self.Attribute(attributeName).Value.ToLowerInvariant() :
self.Attribute(attributeName).Value;
}
示例15: IsAttributeSetToValue
internal static bool IsAttributeSetToValue(this XElement element, string attributeName, string expectedValue)
{
return element.Attribute(attributeName) != null
? string.Equals(
element.Attribute(attributeName).Value,
expectedValue,
StringComparison.InvariantCultureIgnoreCase)
: false;
}