本文整理匯總了C#中System.Xml.Linq.XElement.TryAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.TryAttribute方法的具體用法?C# XElement.TryAttribute怎麽用?C# XElement.TryAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.TryAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: LoadSound
private SoundInfo LoadSound(XElement soundNode, string basePath)
{
SoundInfo sound = new SoundInfo { Name = soundNode.RequireAttribute("name").Value };
sound.Loop = soundNode.TryAttribute<bool>("loop");
sound.Volume = soundNode.TryAttribute<float>("volume", 1);
XAttribute pathattr = soundNode.Attribute("path");
XAttribute trackAttr = soundNode.Attribute("track");
if (pathattr != null)
{
sound.Type = AudioType.Wav;
sound.Path = FilePath.FromRelative(pathattr.Value, basePath);
}
else if (trackAttr != null)
{
sound.Type = AudioType.NSF;
int track;
if (!trackAttr.Value.TryParse(out track) || track <= 0) throw new GameXmlException(trackAttr, "Sound track attribute must be an integer greater than zero.");
sound.NsfTrack = track;
sound.Priority = soundNode.TryAttribute<byte>("priority", 100);
}
else
{
sound.Type = AudioType.Unknown;
}
return sound;
}
示例2: Load
public EntityPlacement Load(XElement node)
{
EntityPlacement info = new EntityPlacement();
info.Id = node.TryAttribute("id", Guid.NewGuid().ToString());
info.entity = node.TryAttribute("name", node.GetAttribute<string>("entity"));
info.state = node.TryAttribute("state", "Start");
info.screenX = node.GetAttribute<int>("x");
info.screenY = node.GetAttribute<int>("y");
var dirAttr = node.Attribute("direction");
if (dirAttr != null)
{
Direction dir = Direction.Left;
Enum.TryParse<Direction>(dirAttr.Value, true, out dir);
info.direction = dir;
}
var respawnAttr = node.Attribute("respawn");
if (respawnAttr != null)
{
RespawnBehavior respawn = RespawnBehavior.Offscreen;
Enum.TryParse<RespawnBehavior>(respawnAttr.Value, true, out respawn);
info.respawn = respawn;
}
return info;
}
示例3: LoadAutoscrollCommand
public static SceneAutoscrollCommandInfo LoadAutoscrollCommand(XElement node)
{
var info = new SceneAutoscrollCommandInfo();
info.Speed = node.TryAttribute<double>("speed", 1);
info.StartX = node.TryAttribute<int>("startX", 128);
return info;
}
示例4: LoadRangeFilter
public RangeFilter LoadRangeFilter(XElement node)
{
if (node == null)
return null;
return new RangeFilter() {
Min = node.TryAttribute<float?>("min"),
Max = node.TryAttribute<float?>("max")
};
}
示例5: LoadVelocity
private VelocityEffectInfo LoadVelocity(XElement prop)
{
if (prop == null)
return null;
var dir = prop.TryAttribute<string>("direction", "Same");
return new VelocityEffectInfo() {
Magnitude = prop.TryAttribute<float?>("magnitude"),
MagnitudeVarName = prop.TryAttribute<string>("magnitudeVar"),
Direction = (MovementEffectDirection)Enum.Parse(typeof(MovementEffectDirection), dir)
};
}
示例6: Load
public SceneCommandInfo Load(XElement node, string basePath)
{
var info = new ScenePlayCommandInfo();
info.Track = node.TryAttribute<int>("nsftrack", node.TryAttribute<int>("track"));
XElement intro = node.Element("Intro");
XElement loop = node.Element("Loop");
info.IntroPath = (intro != null) ? FilePath.FromRelative(intro.Value, basePath) : null;
info.LoopPath = (loop != null) ? FilePath.FromRelative(loop.Value, basePath) : null;
return info;
}
示例7: Load
public IComponentInfo Load(XElement node, Project project)
{
var component = new CollisionComponentInfo();
foreach (var boxnode in node.Elements("Hitbox"))
{
var box = GetHitbox(boxnode);
foreach (var groupnode in boxnode.Elements("Hits"))
box.Hits.Add(groupnode.Value);
foreach (var groupnode in boxnode.Elements("Group"))
box.Groups.Add(groupnode.Value);
foreach (var resistNode in boxnode.Elements("Resist"))
{
var resistName = resistNode.GetAttribute<string>("name");
float mult = resistNode.GetAttribute<float>("multiply");
box.Resistance.Add(resistName, mult);
}
component.HitBoxes.Add(box);
}
component.Enabled = node.TryAttribute<bool>("Enabled");
return component;
}
示例8: LoadMenuState
private static MenuStateInfo LoadMenuState(XElement node, string basePath)
{
var info = new MenuStateInfo();
info.Name = node.RequireAttribute("name").Value;
info.Fade = node.TryAttribute<bool>("fade");
var startNode = node.Element("SelectOption");
if (startNode != null)
{
var startNameAttr = startNode.Attribute("name");
var startVarAttr = startNode.Attribute("var");
if (startNameAttr != null)
{
info.StartOptionName = startNameAttr.Value;
}
if (startVarAttr != null)
{
info.StartOptionVar = startVarAttr.Value;
}
}
info.Commands = LoadCommands(node, basePath);
return info;
}
示例9: Load
public IEffectPartInfo Load(XElement partNode)
{
return new AddInventoryEffectPartInfo() {
ItemName = partNode.RequireAttribute("item").Value,
Quantity = partNode.TryAttribute<int>("quantity", 1)
};
}
示例10: Load
public SceneCommandInfo Load(XElement node, string basePath)
{
var info = new SceneTextCommandInfo();
info.Content = node.TryAttribute<string>("content");
info.Name = node.TryAttribute<string>("name");
info.Speed = node.TryAttribute<int>("speed");
info.X = node.GetAttribute<int>("x");
info.Y = node.GetAttribute<int>("y");
var bindingNode = node.Element("Binding");
if (bindingNode != null) info.Binding = _bindingReader.Load(bindingNode);
info.Font = node.TryAttribute<string>("font");
return info;
}
示例11: Load
public IIncludedObject Load(Project project, XElement xmlNode)
{
var info = new EntityInfo() {
Name = xmlNode.RequireAttribute("name").Value,
MaxAlive = xmlNode.TryAttribute<int>("maxAlive", 50),
GravityFlip = xmlNode.TryElementValue<bool>("GravityFlip"),
Components = new List<IComponentInfo>()
};
ReadEditorData(xmlNode, info);
var deathNode = xmlNode.Element("Death");
if (deathNode != null)
info.Death = _effectReader.Load(deathNode);
foreach (var compReader in ComponentReaders)
{
var element = compReader.NodeName != null ? xmlNode.Element(compReader.NodeName) : xmlNode;
if (element != null)
{
var comp = compReader.Load(element, project);
if (comp != null)
info.Components.Add(comp);
}
}
if (info.PositionComponent == null)
info.Components.Add(new PositionComponentInfo());
if (info.MovementComponent == null && HasMovementEffects(info))
info.Components.Add(new MovementComponentInfo() { EffectInfo = new MovementEffectPartInfo() });
project.AddEntity(info);
return info;
}
示例12: GetHitbox
private static HitBoxInfo GetHitbox(XElement boxnode)
{
float width = boxnode.GetAttribute<float>("width");
float height = boxnode.GetAttribute<float>("height");
float x = boxnode.GetAttribute<float>("x");
float y = boxnode.GetAttribute<float>("y");
var box = new HitBoxInfo() {
Name = boxnode.TryAttribute<string>("name"),
Box = new Common.Geometry.RectangleF(x, y, width, height),
ContactDamage = boxnode.TryAttribute<float>("damage"),
Environment = boxnode.TryAttribute<bool>("environment", true),
PushAway = boxnode.TryAttribute<bool>("pushaway", true),
PropertiesName = boxnode.TryAttribute<string>("properties", "Default")
};
return box;
}
示例13: Load
public IComponentInfo Load(XElement node, Project project)
{
var comp = new HealthComponentInfo();
comp.Max = node.TryAttribute<float>("max", node.TryElementValue<float>("Max"));
comp.StartValue = node.TryAttribute<float?>("startValue");
XElement meterNode = node.Element("Meter");
if (meterNode != null)
{
comp.Meter = _meterReader.LoadMeter(meterNode, project.BaseDir);
}
comp.FlashFrames = node.TryAttribute("flash", node.TryElementValue<int>("Flash"));
return comp;
}
示例14: Load
public IEffectPartInfo Load(XElement partNode)
{
var info = new SpawnEffectPartInfo();
info.Name = partNode.GetAttribute<string>("name");
info.State = partNode.TryAttribute<string>("state", "Start");
info.Position = (PositionEffectPartInfo)_positionReader.Load(partNode);
return info;
}
示例15: CollisionBox
public CollisionBox(XElement xmlNode)
: base(xmlNode)
{
ID = nextID;
nextID++;
Hits = new List<string>();
Groups = new List<string>();
resistance = new Dictionary<string, float>();
Properties = TileProperties.Default;
foreach (XElement groupnode in xmlNode.Elements("Hits"))
{
Hits.Add(groupnode.Value);
}
foreach (XElement groupnode in xmlNode.Elements("Group"))
{
Groups.Add(groupnode.Value);
}
foreach (XElement resistNode in xmlNode.Elements("Resist"))
{
XAttribute nameAttr = resistNode.RequireAttribute("name");
float mult = resistNode.GetAttribute<float>("multiply");
resistance.Add(nameAttr.Value, mult);
}
XAttribute boxnameAttr = xmlNode.Attribute("name");
if (boxnameAttr != null) Name = boxnameAttr.Value;
ContactDamage = xmlNode.TryAttribute<float>("damage");
Environment = xmlNode.TryAttribute<bool>("environment", true);
PushAway = xmlNode.TryAttribute<bool>("pushaway", true);
XAttribute propAttr = xmlNode.Attribute("properties");
if (propAttr != null) Properties = Game.CurrentGame.TileProperties.GetProperties(propAttr.Value);
}