Exemple #1
0
        /// <summary>
        /// Tries to parse the <see cref="GuildID"/> from a string.
        /// </summary>
        /// <param name="parser">The <see cref="Parser"/> to use.</param>
        /// <param name="value">The string to parse.</param>
        /// <param name="outValue">If this method returns true, contains the parsed <see cref="GuildID"/>.</param>
        /// <returns>True if the parsing was successfully; otherwise false.</returns>
        public static bool TryParse(this Parser parser, string value, out GuildID outValue)
        {
            ushort tmp;
            var    ret = parser.TryParse(value, out tmp);

            outValue = new GuildID(tmp);
            return(ret);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GuildBase"/> class.
        /// </summary>
        /// <param name="guildManager">The <see cref="IGuildManager"/> managing this guild.</param>
        /// <param name="id">The unique ID of the guild.</param>
        /// <param name="name">The unique name of the guild.</param>
        /// <param name="tag">The guild's unique tag.</param>
        protected GuildBase(IGuildManager guildManager, GuildID id, string name, string tag)
        {
            _guildManager = guildManager;
            _id           = id;
            _name         = name;
            _tag          = tag;

            // ReSharper disable DoNotCallOverridableMethodsInConstructor
            Save();
            // ReSharper restore DoNotCallOverridableMethodsInConstructor
        }
        /// <summary>
        /// Gets the guild with the specified <paramref name="id"/>.
        /// </summary>
        /// <param name="id">The ID of the guild to get.</param>
        /// <returns>The guild with the specified <paramref name="id"/>, or null if the guild does not exist in this
        /// guild manager.</returns>
        public T GetGuild(GuildID id)
        {
            T ret;

            lock (_guildsSync)
            {
                if (!_guilds.TryGetValue(id, out ret))
                {
                    ret = null;
                }
            }

            return(ret);
        }
Exemple #4
0
 /// <summary>
 /// Writes a <see cref="GuildID"/> to a <see cref="IValueWriter"/>.
 /// </summary>
 /// <param name="valueWriter"><see cref="IValueWriter"/> to write to.</param>
 /// <param name="name">Unique name of the <see cref="GuildID"/> that will be used to distinguish it
 /// from other values when reading.</param>
 /// <param name="value"><see cref="GuildID"/> to write.</param>
 public static void Write(this IValueWriter valueWriter, string name, GuildID value)
 {
     value.Write(valueWriter, name);
 }
Exemple #5
0
 /// <summary>
 /// Writes a <see cref="GuildID"/> to a <see cref="BitStream"/>.
 /// </summary>
 /// <param name="bitStream"><see cref="BitStream"/> to write to.</param>
 /// <param name="value"><see cref="GuildID"/> to write.</param>
 public static void Write(this BitStream bitStream, GuildID value)
 {
     value.Write(bitStream);
 }
Exemple #6
0
 /// <summary>
 /// Reads the <see cref="GuildID"/> from an IValueReader.
 /// </summary>
 /// <param name="valueReader"><see cref="IValueReader"/> to read the <see cref="GuildID"/> from.</param>
 /// <param name="name">The unique name of the value to read.</param>
 /// <returns>The <see cref="GuildID"/> read from the IValueReader.</returns>
 public static GuildID ReadGuildID(this IValueReader valueReader, string name)
 {
     return(GuildID.Read(valueReader, name));
 }
Exemple #7
0
 /// <summary>
 /// Reads the <see cref="GuildID"/> from a <see cref="BitStream"/>.
 /// </summary>
 /// <param name="bitStream"><see cref="BitStream"/> to read the <see cref="GuildID"/> from.</param>
 /// <returns>The <see cref="GuildID"/> read from the <see cref="BitStream"/>.</returns>
 public static GuildID ReadGuildID(this BitStream bitStream)
 {
     return(GuildID.Read(bitStream));
 }
Exemple #8
0
 /// <summary>
 /// Reads the <see cref="GuildID"/> from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="GuildID"/> from.</param>
 /// <param name="name">The name of the field to read the value from.</param>
 /// <returns>The <see cref="GuildID"/> read from the <see cref="IDataRecord"/>.</returns>
 public static GuildID GetGuildID(this IDataRecord r, string name)
 {
     return(GuildID.Read(r, name));
 }
Exemple #9
0
 /// <summary>
 /// Reads the <see cref="GuildID"/> from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="GuildID"/> from.</param>
 /// <param name="i">The field index to read.</param>
 /// <returns>The <see cref="GuildID"/> read from the <see cref="IDataRecord"/>.</returns>
 public static GuildID GetGuildID(this IDataRecord r, int i)
 {
     return(GuildID.Read(r, i));
 }
Exemple #10
0
        /// <summary>
        /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as a
        /// <see cref="GuildID"/>.
        /// </summary>
        /// <typeparam name="T">The key Type.</typeparam>
        /// <param name="dict">The <see cref="IDictionary{TKey, TValue}"/>.</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 GuildID AsGuildID <T>(this IDictionary <T, string> dict, T key, GuildID defaultValue)
        {
            string value;

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

            GuildID parsed;

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

            return(parsed);
        }