internal Provider(System.Xml.XPath.XPathNavigator nav) { this._ProviderName = nav.GetAttribute("name", String.Empty);//.Value; this._ProviderType = nav.GetAttribute("type", String.Empty); var ns = nav.SelectChildren(System.Xml.XPath.XPathNodeType.Element); if (nav.MoveToFirstAttribute()) { if ((nav.Name != "name") & (nav.Name != "type")) { this._ProviderAttributes.Add(nav.Name, nav.Value); } while (nav.MoveToNextAttribute()) { if ((nav.Name != "name") & (nav.Name != "type")) { this._ProviderAttributes.Add(nav.Name, nav.Value); } } } while (ns.MoveNext()) { this._ProviderAttributes.Add(ns.Current.Name, ns.Current.Value); } }
public TowerData(System.Xml.XPath.XPathNavigator xml) { Price = float.Parse(xml.GetAttribute("Price", "")); Name = xml.GetAttribute("Name", ""); ShutdownHeat = float.Parse(xml.GetAttribute("ShutdownHeat", "")); HeatDecay = float.Parse(xml.GetAttribute("HeatDecay", "")); XAML = xml.InnerXml; }
public static void FillParams(Param[] @params, System.Xml.XPath.XPathNavigator nav) { for (int i = 0; i < @params.Length; i++) { @params[i].Value = nav.GetAttribute(@params[i].Name, ""); } }
/// <summary> /// Gets the attribute as double. /// </summary> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="expectEnglish">The expect english.</param> /// <returns></returns> public static double?GetAttributeAsDouble(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, bool expectEnglish = true) { if (null != stdnavi) { try { string tmp = stdnavi.GetAttribute(attributeName, string.Empty); if (expectEnglish) { if (!string.IsNullOrEmpty(tmp)) { return(DataTypeConverter.DoubleConverter.ParseInvariantCulture(tmp)); } } else { if (!string.IsNullOrEmpty(tmp)) { return(DataTypeConverter.DoubleConverter.Parse(tmp)); } } } catch { } } return(null); }
/// <summary> /// Gets the attribute as string. /// </summary> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="selectPath">The select path (or null if no path adjustment needed).</param> /// <param name="defaultValue">The default value.</param> /// <returns></returns> public static string GetAttributeAsString(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, string selectPath, string defaultValue) { if (null != stdnavi) { try { string tmp; if (null != selectPath) { System.Xml.XPath.XPathNavigator navi = AdjustNaviIfNeeded(stdnavi, selectPath); tmp = navi.GetAttribute(attributeName, string.Empty); } else { tmp = stdnavi.GetAttribute(attributeName, string.Empty); } if (string.IsNullOrEmpty(tmp)) { return(defaultValue); } return(tmp); } catch { } } return(defaultValue); }
//public ProjectileType TowerProjectileType; public ProjectileTowerData(System.Xml.XPath.XPathNavigator xml) : base(xml) { //ProjectileTowerData x = new ProjectileTowerData(); //Name = this.Name; //XAML = this.XAML; //Price = this.Price; //TrackingSpeed = this.TrackingSpeed; //Range = this.Range; //RefireDelay = this.RefireDelay; //TowerProjectileType = this.TowerProjectileType; //FiringHeat = this.FiringHeat; Range = float.Parse(xml.GetAttribute("Range", "")); RefireDelay = float.Parse(xml.GetAttribute("RefireDelay", "")); TrackingSpeed = float.Parse(xml.GetAttribute("TrackingSpeed", "")); FiringHeat = float.Parse(xml.GetAttribute("FiringHeat", "")); //return x; }
/// <summary> /// Gets the attribute as int 32. /// </summary> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="defaultValue">The default value.</param> /// <returns></returns> public static Int32 GetAttributeAsInt32(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, Int32 defaultValue) { try { string tmp = stdnavi.GetAttribute(attributeName, string.Empty); if (!string.IsNullOrEmpty(tmp)) { return(DataTypeConverter.Int32Converter.Parse(tmp)); } } catch { } return(defaultValue); }
/// <summary> /// Gets the attribute as time span. /// </summary> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <returns></returns> public static TimeSpan GetAttributeAsTimeSpan(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName) { if (null != stdnavi) { try { string tmp = stdnavi.GetAttribute(attributeName, string.Empty); if (!string.IsNullOrEmpty(tmp)) { return(TimeSpan.Parse(tmp)); } } catch { } } return(TimeSpan.Zero); }
/// <summary> /// Gets the attribute as time span. /// </summary> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="selectPath">The select path.</param> /// <param name="defaultValue">The default value.</param> /// <returns></returns> public static TimeSpan GetAttributeAsTimeSpan(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, string selectPath, TimeSpan defaultValue) { if (null != stdnavi) { try { System.Xml.XPath.XPathNavigator navi = AdjustNaviIfNeeded(stdnavi, selectPath); string tmp = navi.GetAttribute(attributeName, string.Empty); if (!string.IsNullOrEmpty(tmp)) { return(TimeSpan.Parse(tmp)); } } catch { } } return(defaultValue); }
/// <summary> /// Gets the attribute as unsigned int 32. /// </summary> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="selectPath">The select path.</param> /// <param name="defaultValue">The default value.</param> /// <returns></returns> public static UInt32 GetAttributeAsUInt32(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, string selectPath, UInt32 defaultValue) { if (null != stdnavi) { try { System.Xml.XPath.XPathNavigator navi = AdjustNaviIfNeeded(stdnavi, selectPath); string tmp = navi.GetAttribute(attributeName, string.Empty); if (!string.IsNullOrEmpty(tmp)) { return(DataTypeConverter.UInt32Converter.Parse(tmp)); } } catch { } } return(defaultValue); }
/// <summary> /// Gets the attribute as bool. /// </summary> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="defaultValue">The default value.</param> /// <returns></returns> public static bool GetAttributeAsBool(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, bool defaultValue = false) { if (null != stdnavi) { try { string tmp = stdnavi.GetAttribute(attributeName, string.Empty); if (string.IsNullOrEmpty(tmp)) { return(defaultValue); } return(DataTypeConverter.BoolConverter.Parse(tmp)); } catch { } } return(defaultValue); }
/// <summary> /// Tries to parse an enum value from an attribute. /// Does NOT throw any exceptions. /// </summary> /// <typeparam name="T">The type of the T.</typeparam> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="result">Successfully parsed enum value (return true) or enum default value (return false).</param> /// <returns>True if attribute was set (not empty) and was successfully parsed.</returns> public static bool GetAttributeAsEnum <T>(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, out T result) { result = default(T); if (null != stdnavi) { try { string tmp = stdnavi.GetAttribute(attributeName, string.Empty); if (!string.IsNullOrEmpty(tmp)) { //string strAdditionalData = stringHelper.GetSubstringInsideOf("[", "]", tmp); string enumPart = tmp.Truncate("[", false).Trim(); result = (T)Enum.Parse(typeof(T), enumPart); return(true); } } catch { } } return(false); }
public HeatTowerData(System.Xml.XPath.XPathNavigator xml) : base(xml) { HeatAbsorb = float.Parse(xml.GetAttribute("HeatAbsorb", "")); //ProjectileTowerData x = new ProjectileTowerData(); //Name = this.Name; //XAML = this.XAML; //Price = this.Price; //ShutdownHeat = this.ShutdownHeat; //TrackingSpeed = this.TrackingSpeed; //Range = this.Range; //RefireDelay = this.RefireDelay; //TowerProjectileType = this.TowerProjectileType; //FiringHeat = this.FiringHeat; //return x; }
/// <summary> /// Tries to parse an enum value from an attribute. /// Does NOT throw any exceptions. /// </summary> /// <typeparam name="T">The type of the T.</typeparam> /// <param name="stdnavi">The navigator.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="result">Successfully parsed enum value (return true) or enum default value (return false).</param> /// <param name="additionalData">Additional data for each parsed enum value (optional).</param> /// <returns>True if attribute was set (not empty) and was successfully parsed.</returns> public static bool GetAttributeAsEnumList <T>(this System.Xml.XPath.XPathNavigator stdnavi, string attributeName, out System.Collections.Generic.List <T> result, out System.Collections.Generic.List <string> additionalData) { result = new System.Collections.Generic.List <T>(); additionalData = new System.Collections.Generic.List <string>(); string list = null; if (null != stdnavi) { list = stdnavi.GetAttribute(attributeName, string.Empty); } if (string.IsNullOrEmpty(list)) { return(false); } list = list.Replace(';', ','); list = list.Replace('|', ','); foreach (string item in list.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { item.Trim(); if (!string.IsNullOrEmpty(item)) { try { string strAdditionalData = StringHelper.GetSubstringInsideOf("[", "]", item); string enumPart = item.Truncate("[", false).Trim(); result.Add((T)Enum.Parse(typeof(T), enumPart)); additionalData.Add(strAdditionalData); } catch { } } } return(true); }
public static BattlelordsRace LoadFromXml(System.Xml.XPath.XPathNavigator nav) { return(new BattlelordsRace(nav.GetAttribute("name", ""))); }