コード例 #1
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Tries to parse the ShopID from a string.
        /// </summary>
        /// <param name="parser">The Parser to use.</param>
        /// <param name="value">The string to parse.</param>
        /// <param name="outValue">If this method returns true, contains the parsed ShopID.</param>
        /// <returns>True if the parsing was successfully; otherwise false.</returns>
        public static bool TryParse(this Parser parser, string value, out ShopID outValue)
        {
            ushort tmp;
            var    ret = parser.TryParse(value, out tmp);

            outValue = new ShopID(tmp);
            return(ret);
        }
コード例 #2
0
ファイル: ShopBase.cs プロジェクト: thepirateclub/netgore
        /// <summary>
        /// Initializes a new instance of the <see cref="ShopBase{TShopItem}"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        /// <param name="canBuy">Whether or not the shop can buy items from shoppers.</param>
        /// <param name="shopItems">The shop items.</param>
        /// <exception cref="ArgumentOutOfRangeException">The <paramref name="shopItems"/> contains more items than the max
        /// number supported by <see cref="ShopSettings.MaxShopItems"/>.</exception>
        protected ShopBase(ShopID id, string name, bool canBuy, IEnumerable <TShopItem> shopItems)
        {
            _id        = id;
            _name      = string.IsNullOrEmpty(name) ? "Unnamed Shop" : name;
            _canBuy    = canBuy;
            _shopItems = shopItems == null ? _emptyShopItems : shopItems.ToArray();

            if (_shopItems.Length > _shopSettings.MaxShopItems)
            {
                const string errmsg = "There are too many items in the shop `{0}` ({1} > {2})!";
                var          err    = string.Format(errmsg, this, _shopItems.Length, _shopSettings.MaxShopItems);
                log.Fatal(err);
                Debug.Fail(err);
                throw new ArgumentOutOfRangeException(err, "shopItems");
            }
        }
コード例 #3
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as type ShopID.
        /// </summary>
        /// <typeparam name="T">The key Type.</typeparam>
        /// <param name="dict">The IDictionary.</param>
        /// <param name="key">The key for the value to get.</param>
        /// <param name="defaultValue">The value to use if the value at the <paramref name="key"/> could not be parsed.</param>
        /// <returns>The value at the given <paramref name="key"/> parsed as an int, or the
        /// <paramref name="defaultValue"/> if the <paramref name="key"/> did not exist in the <paramref name="dict"/>
        /// or the value at the given <paramref name="key"/> could not be parsed.</returns>
        public static ShopID AsShopID <T>(this IDictionary <T, string> dict, T key, ShopID defaultValue)
        {
            string value;

            if (!dict.TryGetValue(key, out value))
            {
                return(defaultValue);
            }

            ShopID parsed;

            if (!Parser.Invariant.TryParse(value, out parsed))
            {
                return(defaultValue);
            }

            return(parsed);
        }
コード例 #4
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Writes a ShopID to a IValueWriter.
 /// </summary>
 /// <param name="valueWriter">IValueWriter to write to.</param>
 /// <param name="name">Unique name of the ShopID that will be used to distinguish it
 /// from other values when reading.</param>
 /// <param name="value">ShopID to write.</param>
 public static void Write(this IValueWriter valueWriter, string name, ShopID value)
 {
     value.Write(valueWriter, name);
 }
コード例 #5
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Writes a ShopID to a BitStream.
 /// </summary>
 /// <param name="bitStream">BitStream to write to.</param>
 /// <param name="value">ShopID to write.</param>
 public static void Write(this BitStream bitStream, ShopID value)
 {
     value.Write(bitStream);
 }
コード例 #6
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Reads the ShopID from an IValueReader.
 /// </summary>
 /// <param name="valueReader">IValueReader to read the ShopID from.</param>
 /// <param name="name">The unique name of the value to read.</param>
 /// <returns>The ShopID read from the IValueReader.</returns>
 public static ShopID ReadShopID(this IValueReader valueReader, string name)
 {
     return(ShopID.Read(valueReader, name));
 }
コード例 #7
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Reads the ShopID from a BitStream.
 /// </summary>
 /// <param name="bitStream">BitStream to read the ShopID from.</param>
 /// <returns>The ShopID read from the BitStream.</returns>
 public static ShopID ReadShopID(this BitStream bitStream)
 {
     return(ShopID.Read(bitStream));
 }
コード例 #8
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Reads the ShopID from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the ShopID from.</param>
 /// <param name="name">The name of the field to read the value from.</param>
 /// <returns>The ShopID read from the <see cref="IDataRecord"/>.</returns>
 public static ShopID GetShopID(this IDataRecord r, string name)
 {
     return(ShopID.Read(r, name));
 }
コード例 #9
0
ファイル: ShopID.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Reads the ShopID from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the ShopID from.</param>
 /// <param name="i">The field index to read.</param>
 /// <returns>The ShopID read from the <see cref="IDataRecord"/>.</returns>
 public static ShopID GetShopID(this IDataRecord r, int i)
 {
     return(ShopID.Read(r, i));
 }