本文整理匯總了C#中System.Xml.Linq.XElement.RequireAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.RequireAttribute方法的具體用法?C# XElement.RequireAttribute怎麽用?C# XElement.RequireAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.RequireAttribute方法的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: ParseEffect
public static Effect ParseEffect(XElement effectNode)
{
var name = effectNode.RequireAttribute("name").Value;
var value = effectNode.RequireAttribute("value").Value;
return e => { e.GetComponent<VarsComponent>().Set(name, value); };
}
示例3: Load
public SceneBindingInfo Load(XElement node)
{
var info = new SceneBindingInfo();
info.Source = node.RequireAttribute("source").Value;
info.Target = node.RequireAttribute("target").Value;
return info;
}
示例4: PaletteFromXml
private PaletteInfo PaletteFromXml(XElement node, string baseDir)
{
var palette = new PaletteInfo();
var imagePathRelative = node.RequireAttribute("image").Value;
palette.ImagePath = FilePath.FromRelative(imagePathRelative, baseDir);
palette.Name = node.RequireAttribute("name").Value;
return palette;
}
示例5: Load
public void Load(Project project, XElement node)
{
var palette = new PaletteInfo();
var imagePathRelative = node.RequireAttribute("image").Value;
palette.ImagePath = FilePath.FromRelative(imagePathRelative, project.BaseDir);
palette.Name = node.RequireAttribute("name").Value;
project.AddPalette(palette);
}
示例6: 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;
}
示例7: 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;
}
示例8: Entity
public Entity(XElement xmlNode, string basePath)
{
Name = xmlNode.RequireAttribute("name").Value;
// find the primary sprite
var spriteNode = xmlNode.Element("Sprite");
if (spriteNode != null)
{
// if it doesn't have a tilesheet, use the first for the entity
var sheetNode = xmlNode.Element("Tilesheet");
if (sheetNode == null)
{
MainSprite = Sprite.FromXml(spriteNode, basePath);
}
else
{
string sheetPath = System.IO.Path.Combine(basePath, sheetNode.Value);
var sheet = Image.FromFile(sheetPath);
MainSprite = Sprite.FromXml(spriteNode, sheet);
}
MainSprite.Play();
Program.AnimateTick += Program_FrameTick;
}
}
示例9: Load
public IEffectPartInfo Load(XElement partNode)
{
return new AddInventoryEffectPartInfo() {
ItemName = partNode.RequireAttribute("item").Value,
Quantity = partNode.TryAttribute<int>("quantity", 1)
};
}
示例10: FromXml
public static InventoryInfo FromXml(XElement inventoryNode, string basePath)
{
InventoryInfo info = new InventoryInfo();
info.Name = inventoryNode.RequireAttribute("name").Value;
var useAttr = inventoryNode.Attribute("use");
if (useAttr != null)
{
info.UseFunction = useAttr.Value;
}
var iconNode = inventoryNode.Element("Icon");
if (iconNode != null)
{
info.IconOn = FilePath.FromRelative(iconNode.RequireAttribute("on").Value, basePath);
info.IconOff = FilePath.FromRelative(iconNode.RequireAttribute("off").Value, basePath);
}
info.IconLocation = new Point(iconNode.GetInteger("x"), iconNode.GetInteger("y"));
var numberNode = inventoryNode.Element("Number");
if (numberNode != null)
{
info.NumberLocation = new Point(numberNode.GetInteger("x"), numberNode.GetInteger("y"));
}
bool b = true;
inventoryNode.TryBool("selectable", out b);
info.Selectable = b;
return info;
}
示例11: Load
public SceneCommandInfo Load(XElement node, string basePath)
{
var info = new SceneSoundCommandInfo();
info.SoundInfo = new SoundInfo { Name = node.RequireAttribute("name").Value };
return info;
}
示例12: LoadSprite
public Sprite LoadSprite(XElement element, string basePath)
{
var sprite = LoadSprite(element);
var tileattr = element.RequireAttribute("tilesheet");
sprite.SheetPath = FilePath.FromRelative(tileattr.Value, basePath);
return sprite;
}
示例13: Load
public SceneCommandInfo Load(XElement node, string basePath)
{
var info = new SceneAddCommandInfo();
var nameAttr = node.Attribute("name");
if (nameAttr != null) info.Name = nameAttr.Value;
info.Object = node.RequireAttribute("object").Value;
info.X = node.GetAttribute<int>("x");
info.Y = node.GetAttribute<int>("y");
return info;
}
示例14: FromXml
public static PauseWeaponInfo FromXml(XElement weaponNode, string basePath)
{
PauseWeaponInfo info = new PauseWeaponInfo();
info.Name = weaponNode.RequireAttribute("name").Value;
info.Weapon = weaponNode.RequireAttribute("weapon").Value;
info.IconOn = FilePath.FromRelative(weaponNode.RequireAttribute("on").Value, basePath);
info.IconOff = FilePath.FromRelative(weaponNode.RequireAttribute("off").Value, basePath);
info.Location = new Point(weaponNode.GetInteger("x"), weaponNode.GetInteger("y"));
XElement meter = weaponNode.Element("Meter");
if (meter != null)
{
info.Meter = MeterInfo.FromXml(meter, basePath);
}
return info;
}
示例15: Load
public HandlerTransfer Load(XElement node)
{
HandlerTransfer transfer = new HandlerTransfer();
var modeAttr = node.Attribute("mode");
var mode = HandlerMode.Next;
if (modeAttr != null)
{
Enum.TryParse<HandlerMode>(modeAttr.Value, true, out mode);
}
transfer.Mode = mode;
if (mode == HandlerMode.Push)
{
transfer.Pause = node.TryAttribute<bool>("pause");
}
if (mode != HandlerMode.Pop)
{
switch (node.RequireAttribute("type").Value.ToLower())
{
case "stage":
transfer.Type = HandlerType.Stage;
break;
case "scene":
transfer.Type = HandlerType.Scene;
break;
case "menu":
transfer.Type = HandlerType.Menu;
break;
}
transfer.Name = node.RequireAttribute("name").Value;
}
transfer.Fade = node.TryAttribute<bool>("fade");
return transfer;
}