コード例 #1
0
        private List <Action <ValueBag> > CompileImportActions(XElement statement, ValueBag validAssignments)
        {
            List <Action <ValueBag> > actions = new List <Action <ValueBag> >();

            foreach (var stmt in statement.Elements())
            {
                switch (stmt.Name.LocalName.ToLower())
                {
                case "console.print":
                    actions.Add((data) => this.console.Print(stmt.Value, data));
                    break;

                case "console.warn":
                    actions.Add((data) => this.console.Warn(stmt.Value, data));
                    break;

                case "console.error":
                    actions.Add((data) => this.console.Error(stmt.Value, data));
                    break;

                case "console.debug":
                    actions.Add((data) => this.console.Debug(stmt.Value, data));
                    break;

                case "let":
                    // a setter takes the form of
                    //   <let propertyname="column name" default="default value"><values><add text="if this" value="then this value" /></values></let>
                    // we need to validate that the setters propertyname is valid
                    var assignment = new Setter(stmt);

                    if (validAssignments.ContainsKey(assignment.Target))
                    {
                        actions.Add((data) => assignment.Assign(data["sourceValues"], data["targetValues"]));
                    }
                    else
                    {
                        this.log.Warn(string.Format("'{0}' is not a valid assignment attribute. Assignment skipped.", assignment.Target));
                    }
                    break;
                }
            }

            return(actions);
        }