本文整理汇总了C#中System.Xml.Linq.XElement.Attr方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.Attr方法的具体用法?C# XElement.Attr怎么用?C# XElement.Attr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.Attr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromXml
private static IconDef FromXml(XElement xml, PackagePart part)
{
var icon = xml.Attr<string>("icon");
if (icon != null)
icon = part.GetRelationship(icon).TargetUri.OriginalString;
return new IconDef { Icon = icon, Pattern = xml.Attr<string>("pattern")};
}
示例2: LoadFromXml
public static PropertyDef LoadFromXml(XElement xml)
{
var name = xml.Attr<string>("name");
string kindStr = xml.Attr("textKind", "Free");
PropertyTextKind kind;
switch (kindStr)
{
case "Free":
kind = PropertyTextKind.FreeText;
break;
case "Enum":
kind = PropertyTextKind.Enumeration;
break;
case "Tokens":
kind = PropertyTextKind.Tokens;
break;
default:
throw new InvalidFileFormatException(
string.Format("Unknown value '{0}' for textKind attribute (Property = {1})",
kindStr, name));
}
return new PropertyDef
{
Name = name,
Type = xml.Attr<PropertyType>("type"),
IgnoreText = xml.Attr<bool>("ignoreText"),
TextKind = kind,
Hidden = xml.Attr<bool>("hidden")
};
}
示例3: ReadPackage
private LoadPackage ReadPackage(XElement pkge) {
var result = new LoadPackage {Code = pkge.Attr("code")};
var level = pkge.Attr("level");
if (!string.IsNullOrWhiteSpace(level)) {
result.Level = (LoadLevel) Enum.Parse(typeof (LoadLevel), level, true);
}
result.Arm = pkge.Attr("arm","default");
result.Command = pkge.Attr("command", "");
var deps = pkge.Elements("uses");
foreach (var dep in deps) {
result.Dependency.Add(dep.Attr("code"));
}
foreach (var item in pkge.Elements("load")) {
result.Items.Add(ReadItem(item));
}
foreach (var item in pkge.Elements("widget")) {
ReadWidget(result, item);
}
return result;
}
示例4: BoolToAttribute
public void BoolToAttribute() {
var el = new XElement("data");
el.Attr("foo", true);
el.Attr("bar", false);
Assert.That(el.Attribute("foo").Value, Is.EqualTo("true"));
Assert.That(el.Attribute("bar").Value, Is.EqualTo("false"));
}
示例5: LoadFromXml
internal static DeckSectionDef LoadFromXml(XElement xml)
{
return new DeckSectionDef
{
Name = xml.Attr<string>("name"),
Group = xml.Attr<string>("group")
};
}
示例6: LoadFromXml
internal static new At LoadFromXml(XElement xml)
{
return new At
{
group = xml.Attr<string>("group"),
position = xml.Attr<string>("position")
};
}
示例7: LoadFromXml
internal static CardDef LoadFromXml(XElement xml, PackagePart part)
{
var backUri = xml.Attr<string>("back");
if (backUri != null) backUri = part.GetRelationship(backUri).TargetUri.OriginalString;
var frontUri = xml.Attr<string>("front");
if (frontUri != null) frontUri = part.GetRelationship(frontUri).TargetUri.OriginalString;
var cd = new CardDef
{
back = backUri,
front = frontUri,
Width = xml.Attr<int>("width"),
Height = xml.Attr<int>("height"),
CornerRadius = xml.Attr<int>("cornerRadius"),
//Properties = xml.Elements(Defs.XmlnsOctgn + "property")
// //.Select(PropertyDef.LoadFromXml)
// .ToDictionary(x => x.Name)
};
var list = xml.Elements(Defs.XmlnsOctgn + "property");
var proplist = new Dictionary<string,PropertyDef>();
foreach (var l in list)
{
var name = l.Attr<string>("name");
string kindStr = l.Attr("textKind", "Free");
PropertyTextKind kind;
switch (kindStr)
{
case "Free":
kind = PropertyTextKind.FreeText;
break;
case "Enum":
kind = PropertyTextKind.Enumeration;
break;
case "Tokens":
kind = PropertyTextKind.Tokens;
break;
default:
throw new InvalidFileFormatException(
string.Format("Unknown value '{0}' for textKind attribute (Property = {1})",
kindStr, name));
}
var prop = new PropertyDef
{
Name = name,
Type = l.Attr<PropertyType>("type"),
IgnoreText = l.Attr<bool>("ignoreText"),
TextKind = kind,
Hidden = l.Attr<bool>("hidden")
};
proplist.Add(name,prop);
}
cd.Properties = proplist;
return cd;
}
示例8: XsltTask
public XsltTask(IBSharpProject project, XElement definition)
{
this.Project = project;
this.TemplateUri = new Uri(definition.Attr("template"));
this.ClassSelector = new Uri(definition.Attr("selector"));
this.Batch = definition.Attr("batch").ToBool();
this.OutputPath = new Uri(definition.Attr("output"));
this.NoXml = definition.Attr("noxml").ToBool();
this._resolver = new ProjectUriResolver(project);
}
示例9: ContextSwitch
public void ContextSwitch()
{
var el = new XElement("data");
el.With(new {foo = "bar"})
.ToAttr(o => o.foo)
.With(new {bar = "baz"})
.ToAttr(o => o.bar);
Assert.That(el.Attr<string>("foo"), Is.EqualTo("bar"));
Assert.That(el.Attr<string>("bar"), Is.EqualTo("baz"));
}
示例10: LoadFromXml
internal static new AddMarker LoadFromXml(XElement xml)
{
var res = new AddMarker
{
markerId = xml.Attr<Guid?>("id", null),
markerName = xml.Attr<string>("name"),
quantity = xml.Attr<string>("qty", "1")
};
res.LoadBaseFromXml(xml);
return res;
}
示例11: Execute
public override void Execute(XElement el){
string[] codes = Split
? el.Attr("code").SmartSplit(false, true, ',', '/', ';', ' ').ToArray()
: new[]{el.Attr("code")};
string value = el.Value;
foreach (string code in codes){
lock (_project.Global){
_project.Global.Set(code, value);
}
}
}
示例12: LoadFromXml
internal new static ActionDef LoadFromXml(XElement xml)
{
return new ActionDef
{
Name = xml.Attr<string>("menu"),
DefaultAction = xml.Attr<bool>("default"),
Shortcut = xml.Attr<string>("shortcut"),
Execute = xml.Attr<string>("execute"),
BatchExecute = xml.Attr<string>("batchExecute")
};
}
示例13: Resource
internal Resource(ResourceSet parent, XElement xe)
{
ParentSet = parent;
Path = xe.Attr<string>(SchemaConstants.Resource.Path);
Mode = xe.Attr(SchemaConstants.Resource.Mode, Default.Resource.Mode);
ForwardCookie = xe.Attr(SchemaConstants.Resource.ForwardCookie,
Default.Resource.ForwardCookie);
Minifier = ParentSet.Type == ResourceType.JS
? ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.JSMinifierMap)
: ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.CssMinifierMap);
if (Mode == ResourceMode.Static && ForwardCookie)
throw new XmlSchemaException("ForwardCookie must not be True when Mode is Static");
}
示例14: RenameElement
private void RenameElement(XElement gj, XElement e, XElement[] selection)
{
var targetattr = gj.Attr("targetattr");
var newname = gj.Attr("newname");
foreach(var s in selection)
{
if (!string.IsNullOrWhiteSpace(targetattr))
{
s.SetAttributeValue(targetattr, s.Name.LocalName);
}
s.Name = newname;
}
}
示例15: ReadWidget
private void ReadWidget(LoadPackage result, XElement item) {
var level = LoadLevel.Guest;
var levele = item.Attr("level");
if (!string.IsNullOrWhiteSpace(levele))
{
level = (LoadLevel)Enum.Parse(typeof(LoadLevel), levele, true);
}
var code = item.Attr("code");
var command = item.Attr("command");
result.Items.Add(new LoadItem {Level = level, Command=command, Type = LoadItemType.Script, Value = code + ".js"});
result.Items.Add(new LoadItem { Level = level, Command=command, Type = LoadItemType.Style, Value = code + ".css" });
result.Items.Add(new LoadItem { Level = level, Command = command, Type = LoadItemType.Template, Value = code + ".tpl.html" });
}