Esempio n. 1
0
        object GetThing(Variable variable)
        {
            // Any values the user specifies have priority. This allows you to override
            // what the USER variable means for example.
            object thing = "";

            if (VariableValues != null &&
                !String.IsNullOrEmpty(variable.Name) &&
                VariableValues.TryGetValue(variable.Name, out thing))
            {
                log.DebugFormat(CultureInfo.InvariantCulture, "GetThing for variable {0}, found entry in VariableValues of {1}", variable.Name, thing);
                return(thing);
            }

            // Given the user an opportunity to replace via an event.
            // If this is a built in variable try use it to initialise the Thing.
            var e = OnVariableReplacement;

            if (e != null)
            {
                object variableVal = null;
                try
                {
                    variableVal = AutoZillaVariables.GetByName(variable.Name);
                }
                catch
                {
                }

                var args = new VariableReplacementEventArgs(variable.Name, variableVal);

                e(this, args);
                if (args.Thing != null)
                {
                    log.DebugFormat(CultureInfo.InvariantCulture, "GetThing for variable {0}, event handler supplied the value {1}", variable.Name, args.Thing);
                    return(args.Thing);
                }
            }

            // Deal with all built in variables. This will throw if the
            // variable is not found.
            thing = AutoZillaVariables.GetByName(variable.Name);
            log.DebugFormat(CultureInfo.InvariantCulture, "GetThing for variable {0}, used built-in value of {1}", variable.Name, thing);
            return(thing);
        }
Esempio n. 2
0
 void NoOpVariableReplacementViaEventsWorks_OnVariableReplacement(object sender, VariableReplacementEventArgs e)
 {
 }
Esempio n. 3
0
 void VariableReplacementViaEventsWorks_OnVariableReplacement(object sender, VariableReplacementEventArgs e)
 {
     e.Thing = DUMMY_VALUE;
 }