/// <summary>Registers a global variable.</summary>
 /// <exception cref="Exception">Thrown an exception if the global variable name already exists.</exception>
 /// <param name="name">The global variable name.</param>
 /// <param name="value">The global variable value.</param>
 /// <returns>An Fluent EvalContext.</returns>
 public EvalContext RegisterGlobalVariable(string name, object value)
 {
     if (!AliasGlobalVariables.TryAdd(name, value))
     {
         throw new Exception(string.Format(ExceptionMessage.UnexpectedAliasRegistered, name));
     }
     return(this);
 }
Esempio n. 2
0
        /// <summary>Unregisters a global variable.</summary>
        /// <param name="aliases">The global variable name.</param>
        /// <returns>An Fluent EvalContext.</returns>
        public EvalContext UnregisterGlobalVariable(params string[] aliases)
        {
            foreach (var alias in aliases)
            {
                object value;
                AliasGlobalVariables.TryRemove(alias, out value);
            }

            return(this);
        }
        /// <summary>Unregisters all kind of alias (Extension Methods, Names, Static Members, Types and Values).</summary>
        /// <returns>An Fluent EvalContext.</returns>
        public EvalContext UnregisterAll()
        {
            AliasExtensionMethods.Clear();
            AliasGlobalConstants.Clear();
            AliasGlobalVariables.Clear();
            AliasNames.Clear();
            AliasStaticMembers.Clear();
            AliasTypes.Clear();

            return(this);
        }