当前位置: 首页>>代码示例>>C#>>正文


C# XElement.TryAttribute方法代码示例

本文整理汇总了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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:32,代码来源:SoundXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:31,代码来源:EntityPlacementXmlReader.cs

示例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;
        }
开发者ID:laazer,项目名称:cs_megaman,代码行数:9,代码来源:HandlerXmlReader.cs

示例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")
            };
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:10,代码来源:EffectXmlReader.cs

示例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)
            };
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:12,代码来源:MovementEffectPartXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:13,代码来源:PlayCommandXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:28,代码来源:CollisionComponentXmlReader.cs

示例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;
        }
开发者ID:laazer,项目名称:cs_megaman,代码行数:29,代码来源:MenuXmlReader.cs

示例9: Load

 public IEffectPartInfo Load(XElement partNode)
 {
     return new AddInventoryEffectPartInfo() {
         ItemName = partNode.RequireAttribute("item").Value,
         Quantity = partNode.TryAttribute<int>("quantity", 1)
     };
 }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:7,代码来源:AddInventoryEffectPartXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:16,代码来源:TextCommandXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:35,代码来源:EntityXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:17,代码来源:LadderComponentXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:17,代码来源:HealthComponentXmlReader.cs

示例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;
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:10,代码来源:SpawnEffectPartXmlReader.cs

示例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);
        }
开发者ID:laazer,项目名称:cs_megaman,代码行数:42,代码来源:CollisionBox.cs


注:本文中的System.Xml.Linq.XElement.TryAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。