Ejemplo n.º 1
0
        /// <summary>
        /// Sets or Adds a CVar.
        /// </summary>
        /// <typeparam name="T">The datatype of the cvar.</typeparam>
        /// <param name="name">The cvar's name.</param>
        /// <param name="value">The cvar's value.</param>
        public static void SetCVar <T>(string name, T value)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (CVars.ContainsKey(name))
            {
                CVars[name] = new CVar(CVars[name].dtype, value);
            }
            else
            {
                CVars.Add(name, new CVar(typeof(T), value));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets a CVar (infers datatype, slower than SetCVar<T>).
        /// </summary>
        /// <param name="name">The cvar's name.</param>
        /// <param name="value">The cvar's value.</param>
        static void SetCVar(string name, object value)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (CVars.ContainsKey(name))
            {
                CVars[name] = new CVar(CVars[name].dtype, Convert.ChangeType(value, CVars[name].dtype));
            }
            else
            {
                throw new Exception(
                          String.Format("CVar \"{0}\" doesnt exist, and cannot be added! (To add, use AddCVar Or SetCVar<T>)", name));
            }
        }