public static void SetProperties(IAction action) { foreach (PropertyInfo pi in action.GetType().GetProperties()) { object[] propertyAttributes = pi.GetCustomAttributes(typeof(ActionPropertyAttribute), false); if (propertyAttributes.Length == 1) { if (action.Fields.ContainsKey(pi.Name)) { pi.SetValue(action, Convert.ChangeType(ValueStringEvaluator.Evaluate(action.Fields[pi.Name], action.ParentBuildFile), pi.PropertyType), null); action.Fields.Remove(pi.Name); } else { ActionPropertyAttribute apa = (ActionPropertyAttribute)propertyAttributes[0]; if (apa.IsRequired) { throw new ActionPropertyNotSetException(action, pi, "The value for a required property was not set."); } } } } EvaluateFields(action); }
public bool SetPropertyValue(string propertyName, string value) { foreach (Property prop in this.Properties) { if (prop.Name == propertyName) { prop.Value = ValueStringEvaluator.Evaluate(value, this); return(true); } } return(false); }
private void Initialize() { this.rootElements.Clear(); this.properties.Clear(); foreach (XmlElement xe in this.xd.SelectNodes("/CamBuildProject/Property")) { Property prop = (Property)BuildFileElementFactory.Create(xe, this); this.properties.Add(prop); this.SetPropertyValue(prop.Name, ValueStringEvaluator.Evaluate(prop.Value, this)); } this.rootElements = (List <IBuildFileElement>)BuildFileElementParser.Parse(this.xd, this); }
private static void EvaluateFields(IAction action) { Dictionary <string, string> newFields = new Dictionary <string, string>(); foreach (string key in action.Fields.Keys) { newFields.Add(key, ValueStringEvaluator.Evaluate(action.Fields[key], action.ParentBuildFile)); } action.Fields.Clear(); foreach (KeyValuePair <string, string> kvp in newFields) { action.Fields.Add(kvp.Key, kvp.Value); } }
public static string Evaluate(string valueString, BuildFile parentBuildFile) { List <ValueToken> tokens = (List <ValueToken>)ValueStringTokenizer.TokenizeString(valueString); string eval = ""; foreach (ValueToken token in tokens) { if (token.Type == ValueTokenType.Text) { eval += token.Text; } else if (token.Type == ValueTokenType.Function) { FunctionString fs = new FunctionString(token.Text); IFunction bf = FunctionFactory.Create(fs.Name); List <string> newArgs = new List <string>(); foreach (string arg in fs.Args) { // TODO: This will cause a fatal error if function calls are nested newArgs.Add(ValueStringEvaluator.Evaluate(arg, parentBuildFile)); } eval += bf.GetResult(newArgs); } else if (token.Type == ValueTokenType.Property) { if (parentBuildFile == null) { throw new ValueStringEvaluatorException("Value string contains a property, " + "but supplied BuildFile object is null", valueString); } eval += parentBuildFile.GetPropertyValue(token.Text); } } return(eval); }