public override IQueryable ModifyQuery(ExpressionOptions options) { MethodInfo method; var action = default(Delegate); if (!_delegates.TryGetValue(options.Query.GetType(), out action) && options.Query.GetType().TryGetMethod("Include", null, out method)) { var instance = Expression.Parameter(options.Query.GetType(), "i"); var path = Expression.Parameter(typeof(string), "p"); action = Expression.Lambda(Expression.Call(instance, method, path), instance, path).Compile(); _delegates[options.Query.GetType()] = action; } var queryresult = options.Query; if (action != null) { foreach (var child in Children) { queryresult = (IQueryable)action.DynamicInvoke(queryresult, child.Text); } } return(queryresult); }
protected static bool IsOwnerMemberAccessible(MemberInfo member, ExpressionOptions options) { bool accessAllowed = false; // Get the allowed access defined in the options if (IsMemberPublic(member) == true) { accessAllowed = (options.OwnerMemberAccess & BindingFlags.Public) != 0; } else { accessAllowed = (options.OwnerMemberAccess & BindingFlags.NonPublic) != 0; } // See if the member has our access attribute defined ExpressionOwnerMemberAccessAttribute attr = (ExpressionOwnerMemberAccessAttribute)Attribute.GetCustomAttribute(member, typeof(ExpressionOwnerMemberAccessAttribute)); if (attr == null) { // No, so return the access level return(accessAllowed); } else { // Member has our access attribute defined; use its access value instead return(attr.AllowAccess); } }
public object ConvertTo(Project project, Type type, ExpressionOptions options) { if (type.IsArray) { if (type == typeof(ITaskItem[])) { return(ConvertToITaskItemArray(project, options)); } else { return(ConvertToArray(project, type, options)); } } else { if (type == typeof(ITaskItem)) { return(ConvertToITaskItem(project, options)); } else { return(ConvertToNonArray(project, type, options)); } } }
public override Expression BuildLinqExpression(ExpressionOptions options) { var property = options.Item; var alias = this.Children[1].Text; var filter = this.Children[2]; var underlyingType = property.Type; if (typeof(IEnumerable).IsAssignableFrom(property.Type) && property.Type.GetGenericArguments().Any()) { underlyingType = property.Type.GetGenericArguments()[0]; } else { //We will sometimes need to cater for special cases here, such as Enumerating BsonValues //underlyingType = Configuration.EnumerableTypeMap(underlyingType); var enumerable = typeof(IEnumerable <>).MakeGenericType(underlyingType); property = Expression.Convert(property, enumerable); } var parameter = Expression.Parameter(underlyingType, alias); var lambda = Expression.Lambda( filter.BuildLinqExpression(options.Clone().WithItem(parameter)), new[] { parameter }); return(Expression.Call(typeof(Enumerable), "All", new[] { underlyingType }, property, lambda)); }
object ConvertToObject(string raw, Type type, ExpressionOptions options) { if (type == typeof(bool)) { bool value; if (boolValues.TryGetValue(raw, out value)) { return(value); } else { return(false); } } if (type == typeof(string)) { return(raw); } if (type.IsPrimitive) { return(Convert.ChangeType(raw, type)); } if (type == typeof(DateTime)) { return(DateTime.Parse(raw)); } throw new Exception(String.Format("Unsupported type: {0}", type)); }
string ConvertToString(Project project, ExpressionOptions options) { StringBuilder sb = new StringBuilder(); foreach (object o in objects) { string s = o as string; if (s != null) { sb.Append(s); continue; } IReference br = o as IReference; if (br != null) { sb.Append(br.ConvertToString(project, options)); } else { throw new Exception("BUG: Invalid type in objects collection."); } } return(sb.ToString()); }
// when evaluating items: expand: true // all other times, expand: true // so, always true, ignore @options public string ConvertToString(Project project, ExpressionOptions options) { if (project == null) { throw new ArgumentNullException("project"); } if (is_registry) { string val = (String)Registry.GetValue(reg_key, reg_value, String.Empty); return(val); } else { BuildProperty bp = project.EvaluatedProperties[name]; if (bp == null) { return(String.Empty); } if (options == ExpressionOptions.DoNotExpandItemRefs) { return(bp.FinalValue); } return(bp.ConvertToString(project, ExpressionOptions.ExpandItemRefs)); } }
public static LiteralElement CreateFromInteger(string image, IServiceProvider services) { LiteralElement element = default(LiteralElement); element = CreateSingle(image, services); if ((element != null)) { return(element); } element = CreateDecimal(image, services); if ((element != null)) { return(element); } ExpressionOptions options = (ExpressionOptions)services.GetService(typeof(ExpressionOptions)); // Convert to a double if option is set if (options.IntegersAsDoubles == true) { return(DoubleLiteralElement.Parse(image, services)); } return(null); }
public static string Parse(string line, ExpressionOptions options) { if (line.IndexOf("#(") > -1) { MatchCollection matches = _exprTriggerRegEx.Matches(line); int offset = 0; foreach (Match match in matches) { string result; try { result = ParseExpression(match).Evaluate(options).ToString(); } catch (TargetInvocationException ex) { result = ex.InnerException.ToString().Replace('\n', ' ').Replace('\r', ' '); } catch (Exception ex) { result = ex.ToString().Replace('\n', ' ').Replace('\r', ' '); } //line = line.Replace(match.Value, result); line = line.Remove(match.Index + offset, match.Length).Insert(match.Index + offset, result); offset += result.Length - match.Length; } } return(line); }
internal ITaskItem[] ConvertToITaskItemArray(Project project, ExpressionOptions options) { if (converting) { // found ref to @this while trying to ConvertToITaskItemArray // for @this! ITaskItem [] items = new ITaskItem [1]; items [0] = new TaskItem(FinalValue); return(items); } converting = true; try { Expression exp = new Expression(); // in non-evaluation phase, properties are always expanded exp.Parse(FinalValue, ParseOptions.Split | (options == ExpressionOptions.ExpandItemRefs ? ParseOptions.AllowItems : ParseOptions.None)); return((ITaskItem[])exp.ConvertTo(project, typeof(ITaskItem[]), options)); } finally { converting = false; } }
public override Expression BuildLinqExpression(ExpressionOptions options) { var parameter = options.Item ?? Expression.Parameter(options.InputType, "o"); Expression childExpression = options.Expression; var temp = parameter; foreach (var child in this.Children) { childExpression = child.BuildLinqExpression(options.Clone().WithExpression(childExpression).WithItem(temp)); temp = childExpression; } Debug.Assert(childExpression != null, "childExpression should never be null"); var methodName = "OrderBy"; //(query.Provider.GetType().Name.Contains("DbQueryProvider") || query.Provider.GetType().Name.Contains("MongoQueryProvider")) && if (!this.IsFirstChild) { methodName = "ThenBy"; } var lambda = Expression.Lambda(childExpression, new[] { parameter as ParameterExpression }); return(Expression.Call(typeof(Queryable), methodName, new[] { options.Query.ElementType, childExpression.Type }, options.Query.Expression, lambda)); }
// In eval phase, any ref'ed item would've already been expanded // or it doesnt exist, so dont expand again // In non-eval, items have _already_ been expanded, so dont expand again // So, ignore @options internal string ConvertToString(Expression transform, Expression separator, ExpressionOptions options) { string separatorString; // Item refs are not expanded for separator or transform if (separator == null) { separatorString = ";"; } else { separatorString = (string)separator.ConvertTo(parentProject, typeof(string), ExpressionOptions.DoNotExpandItemRefs); } string[] items = new string [buildItems.Count]; int i = 0; foreach (BuildItem bi in buildItems) { items [i++] = bi.ConvertToString(transform, ExpressionOptions.DoNotExpandItemRefs); } return(String.Join(separatorString, items)); }
public ITaskItem [] ConvertToITaskItemArray(Project project, ExpressionOptions options) { List <ITaskItem> items = new List <ITaskItem> (); if (IsQualified) { // Bucket would have item lists with same metadata values, // so just get the value from the first item BuildItemGroup group; if (project.TryGetEvaluatedItemByNameBatched(itemName, out group)) { BuildItemGroupToITaskItems(group, items, true); } } else { // Get unique metadata values from _all_ item lists foreach (BuildItemGroup group in project.GetAllItemGroups()) { BuildItemGroupToITaskItems(group, items, false); } } return(items.Count == 0 ? null : items.ToArray()); }
public override Expression BuildLinqExpression(ExpressionOptions options) { var parameter = options.Item ?? Expression.Parameter(options.InputType, "o"); Expression childExpression = options.Expression; var temp = parameter; foreach (var child in this.Children.Cast <ODataNode>()) { childExpression = child.BuildLinqExpression(options.Clone().WithExpression(childExpression).WithItem(temp)); temp = childExpression; } Debug.Assert(childExpression != null, "childExpression should never be null"); var methodName = "OrderByDescending"; if (!this.IsFirstChild) { methodName = "ThenByDescending"; } var lambda = Expression.Lambda(childExpression, new[] { parameter as ParameterExpression }); return(Expression.Call(typeof(Queryable), methodName, new[] { options.Query.ElementType, childExpression.Type }, options.Query.Expression, lambda)); }
public override Expression BuildLinqExpression(ExpressionOptions options) { if (base.Type == TokenType.Identifier) { var param = options.Item as ParameterExpression; if (param != null && param.Name == this.Text) { return(options.Item); } if (options.DynamicAccessor != null) { return(Expression.Invoke(options.DynamicAccessor, new[] { options.Item, Expression.Constant(this.Text) })); } return(Expression.Property(options.Item, this.Text)); } else { var parent = options.Item; foreach (var child in this.Children) { parent = child.BuildLinqExpression(options.Clone().WithItem(parent)); } return(parent); } }
internal ITaskItem ConvertToITaskItem(Expression transform, ExpressionOptions options) { TaskItem taskItem; taskItem = new TaskItem(GetItemSpecFromTransform(transform, options), evaluatedMetadata); return(taskItem); }
public override object Evaluate(ExpressionOptions options) { // Evaluate if required or if the expression is invalid if ((options & ExpressionOptions.EVALUATE_ALWAYS) > 0 || !IsValid) { int paramCount = _parameters.Length; object[] paramValues = new object[paramCount]; for (int i = 0; i < paramCount; i++) { if (_parameters[i] != null) { paramValues[i] = _parameters[i].Evaluate(options); } else { return(0); } } _value = _func.Invoke(paramValues); if (_value == null) { return(0); } IsValid = true; } return(_value); }
public ITaskItem[] ConvertToITaskItemArray(Project project, ExpressionOptions options) { var items = new ITaskItem[1]; items[0] = new TaskItem(ConvertToString(project, options)); return(items); }
public ITaskItem [] ConvertToITaskItemArray (Project project, ExpressionOptions options) { BuildItemGroup group; if (project.TryGetEvaluatedItemByNameBatched (itemName, out group)) return group.ConvertToITaskItemArray (transform, separator, options); else return null; }
// when evaluating property, allowItems=false, so, // ItemRef will _not_ get created, so this wont get hit // when evaluating items, expand: true // other cases, expand: true public string ConvertToString (Project project, ExpressionOptions options) { BuildItemGroup group; if (project.TryGetEvaluatedItemByNameBatched (itemName, out group)) return group.ConvertToString (transform, separator, options); else return String.Empty; }
internal ExpressionOptions ApplyTo(ExpressionOptions options) { return(options with { EnableFunctions = EnableFunctions ?? options.EnableFunctions, EnableVariables = EnableVariables ?? options.EnableVariables }); }
public void Resolve(IServiceProvider services) { MyServices = services; MyOptions = (ExpressionOptions)services.GetService(typeof(ExpressionOptions)); MyContext = (ExpressionContext)services.GetService(typeof(ExpressionContext)); this.ResolveInternal(); this.Validate(); }
public ISqlExpressionBuilder Select(IEnumerable <string> columns, ExpressionOptions option) { if (option == ExpressionOptions.Overwrite) { _stmtSelect.Expressions.Clear(); } Select(columns); return(this); }
public override Expression BuildLinqExpression(ExpressionOptions options) { return(Expression.Call( typeof(Queryable), "Take", new[] { options.Query.ElementType }, options.Query.Expression, this.ChildNode.BuildLinqExpression(options))); }
public override object Evaluate(ExpressionOptions options) { // Evaluate if required or if the expression is invalid if ((options & ExpressionOptions.EVALUATE_ALWAYS) > 0 || !IsValid) { _value = GUIPropertyManager.GetProperty(_propertyName); IsValid = true; } return(_value); }
object Invoke (Project project, ExpressionOptions options) { var flags = BindingFlags.IgnoreCase | BindingFlags.Public; object target; if (Instance == null) { target = null; flags |= BindingFlags.Static; } else { var mir = Instance as MemberInvocationReference; if (mir != null) { target = mir.Invoke (project, options); if (target == null) { throw new NotImplementedException ("Instance method on null value"); } type = target.GetType (); } else { target = Instance.ConvertToString (project, options); type = typeof (string); } flags |= BindingFlags.Instance; } object[] args; if (Arguments == null) { flags |= BindingFlags.GetProperty; args = null; } else { flags |= BindingFlags.InvokeMethod; ExpandArguments (project, options); args = PrepareMethodArguments (flags); if (args == null) throw new InvalidProjectFileException (string.Format ("Method '{0}({1})' arguments cannot be evaluated'", name, string.Join (", ", Arguments.ToArray ()))); } object value; try { value = type.InvokeMember (name, flags, null, target, args, CultureInfo.InvariantCulture); } catch (MissingFieldException) { // // It can be field/constant instead of a property // if (args == null && Instance == null) { flags &= ~BindingFlags.GetProperty; flags |= BindingFlags.GetField; value = type.InvokeMember (name, flags, null, null, null, CultureInfo.InvariantCulture); } else { throw; } } return value; }
public ISqlExpressionBuilder Order(string column, OrderOptions options, ExpressionOptions expOptions) { ColumnExpression col = _CreateColumnByName(column); if (expOptions == ExpressionOptions.Overwrite) { _stmtOrder.Columns.Clear(); } _stmtOrder.Columns.Add(col, options); return(this); }
public static object ParseExpression(string expressionText, ExpressionOptions options) { //Match match = _functionRegEx.Match(expressionText); Match match = _expressionRegEx.Match(expressionText); if (match != null) { return(ParseExpression(match).Evaluate(options)); } return(null); }
static void TestParse(string expression, ExpressionNode expected, ExpressionOptions options = ExpressionOptions.None) { var expr = ExpressionParser.Parse(expression, options, 0); AssertEqual(expected, expr, 0); const int baseOffset = 123; expr = ExpressionParser.Parse(expression, options, baseOffset); AssertEqual(expected, expr, baseOffset); }
public QbservableServiceOptions(QbservableServiceOptions clone) { Contract.Requires(clone != null); Contract.Ensures(!IsFrozen); sendServerErrorsToClients = clone.sendServerErrorsToClients; enableDuplex = clone.enableDuplex; allowExpressionsUnrestricted = clone.allowExpressionsUnrestricted; expressionOptions = clone.expressionOptions; evaluationContext = clone.evaluationContext; }
public override Expression BuildLinqExpression(ExpressionOptions options) { var child = GetValueNode(); if (child != null) { return(child.BuildLinqExpression(options)); } return(options.Item); }
string GetItemSpecFromTransform(Expression transform, ExpressionOptions options) { StringBuilder sb; if (transform == null) { if (options == ExpressionOptions.ExpandItemRefs) { // With usual code paths, this will never execute, // but letting this be here, incase BI.ConvertTo* // is called directly Expression expr = new Expression(); expr.Parse(finalItemSpec, ParseOptions.AllowItemsNoMetadataAndSplit); return((string)expr.ConvertTo(parent_item_group.ParentProject, typeof(string), ExpressionOptions.ExpandItemRefs)); } else { return(finalItemSpec); } } else { // Transform, _DONT_ expand itemrefs sb = new StringBuilder(); foreach (object o in transform.Collection) { if (o is string) { sb.Append((string)o); } else if (o is PropertyReference) { sb.Append(((PropertyReference)o).ConvertToString( parent_item_group.ParentProject, ExpressionOptions.DoNotExpandItemRefs)); } else if (o is ItemReference) { sb.Append(((ItemReference)o).ConvertToString( parent_item_group.ParentProject, ExpressionOptions.DoNotExpandItemRefs)); } else if (o is MetadataReference) { sb.Append(GetMetadata(((MetadataReference)o).MetadataName)); } } return(sb.ToString()); } }
private void SetupOptions(ExpressionOptions options, bool isGeneric) { // Make sure we clone the options _myOptions = options; _myOptions.IsGeneric = isGeneric; if (isGeneric) { _myOptions.ResultType = typeof(T); } _myOptions.SetOwnerType(_myOwner.GetType()); }
public object ConvertTo (Project project, Type type, ExpressionOptions options) { if (type.IsArray) { if (type == typeof (ITaskItem[])) return ConvertToITaskItemArray (project, options); else return ConvertToArray (project, type, options); } else { if (type == typeof (ITaskItem)) return ConvertToITaskItem (project, options); else return ConvertToNonArray (project, type, options); } }
// when evaluating items: expand: true // all other times, expand: true // so, always true, ignore @options public string ConvertToString (Project project, ExpressionOptions options) { if (project == null) throw new ArgumentNullException ("project"); BuildProperty bp = project.EvaluatedProperties [name]; if (bp == null) return String.Empty; if (options == ExpressionOptions.DoNotExpandItemRefs) return bp.FinalValue; return bp.ConvertToString (project, ExpressionOptions.ExpandItemRefs); }
// when evaluating items: expand: true // all other times, expand: true // so, always true, ignore @options public ITaskItem[] ConvertToITaskItemArray (Project project, ExpressionOptions options) { BuildProperty bp = project.EvaluatedProperties [name]; if (bp == null) return null; if (options == ExpressionOptions.DoNotExpandItemRefs) { List<ITaskItem> list = new List<ITaskItem> (); foreach (string s in bp.FinalValue.Split (new char[] {';'}, StringSplitOptions.RemoveEmptyEntries)) list.Add (new TaskItem (s)); return list.ToArray (); } return bp.ConvertToITaskItemArray (project, ExpressionOptions.ExpandItemRefs); }
public ITaskItem [] ConvertToITaskItemArray (Project project, ExpressionOptions options) { List<ITaskItem> items = new List<ITaskItem> (); if (IsQualified) { // Bucket would have item lists with same metadata values, // so just get the value from the first item BuildItemGroup group; if (project.TryGetEvaluatedItemByNameBatched (itemName, out group)) BuildItemGroupToITaskItems (group, items, true); } else { // Get unique metadata values from _all_ item lists foreach (BuildItemGroup group in project.GetAllItemGroups ()) BuildItemGroupToITaskItems (group, items, false); } return items.Count == 0 ? null : items.ToArray (); }
string ConvertToString (Project project, ExpressionOptions options) { StringBuilder sb = new StringBuilder (); foreach (object o in objects) { string s = o as string; if (s != null) { sb.Append (s); continue; } IReference br = o as IReference; if (br != null) sb.Append (br.ConvertToString (project, options)); else throw new Exception ("BUG: Invalid type in objects collection."); } return sb.ToString (); }
/// <summary> /// Initializes a new instance of the LatexExpression class and copies the specified expression data to it. /// </summary> /// <param name="expression">The expression to clone.</param> public LatexExpression(LatexExpression expression) { Parent = expression.Parent; Name = expression.Name; ExprType = expression.ExprType; MathMode = expression.MathMode; Customization = expression.Customization; if (expression.Options != null) { Options = new ExpressionOptions(); } if (expression.Expressions != null) { Expressions = new List<List<LatexExpression>>(expression.Expressions); } }
// Concat rules (deduced) // - ItemRef can concat only with a string ';' or PropertyRef ending in ';' // - MetadataRef can concat with anything other than ItemRef // - PropertyRef cannot be right after a ItemRef // PropertyRef concats if it doesn't end in ';' // - string cannot concat with ItemRef unless it is ';'. // string concats if it ends in ';' ITaskItem[] ConvertToITaskItemArray (Project project, ExpressionOptions options) { List <ITaskItem> finalItems = new List <ITaskItem> (); object prev = null; bool prev_can_concat = false; foreach (object o in objects) { bool can_concat = prev_can_concat; string str = o as string; if (str != null) { string trimmed_str = str.Trim (); if (!IsSemicolon (str) && trimmed_str.Length > 0 && prev != null && prev is ItemReference) // non-empty, non-semicolon string after item ref ThrowCantConcatError (prev, str); if (trimmed_str.Length == 0 && prev is string && IsSemicolon ((string) prev)) { // empty string after a ';', ignore it continue; } // empty string _after_ a itemref, not an error prev_can_concat = !(str.Length > 0 && str [str.Length - 1] == ';') && trimmed_str.Length > 0; AddItemsToArray (finalItems, ConvertToITaskItemArrayFromString (str), can_concat); prev = o; continue; } IReference br = o as IReference; if (br == null) throw new Exception ("BUG: Invalid type in objects collection."); if (o is ItemReference) { if (prev != null && !(prev is string && (string)prev == ";")) ThrowCantConcatError (prev, br); prev_can_concat = true; } else if (o is MetadataReference) { if (prev != null && prev is ItemReference) ThrowCantConcatError (prev, br); prev_can_concat = true; } else if (o is PropertyReference) { if (prev != null && prev is ItemReference) ThrowCantConcatError (prev, br); string value = ((PropertyReference) o).GetValue (project); prev_can_concat = !(value.Length > 0 && value [value.Length - 1] == ';'); } AddItemsToArray (finalItems, br.ConvertToITaskItemArray (project, options), can_concat); prev = o; } // Trim and Remove empty items List<ITaskItem> toRemove = new List<ITaskItem> (); for (int i = 0; i < finalItems.Count; i ++) { string s = ((ITaskItem2)finalItems [i]).EvaluatedIncludeEscaped.Trim (); if (s.Length == 0) toRemove.Add (finalItems [i]); else ((ITaskItem2)finalItems [i]).EvaluatedIncludeEscaped = s; } foreach (ITaskItem ti in toRemove) finalItems.Remove (ti); return finalItems.ToArray (); }
ITaskItem ConvertToITaskItem (Project project, ExpressionOptions options) { if (objects == null) throw new Exception ("Cannot cast empty expression to ITaskItem."); ITaskItem[] items = ConvertToITaskItemArray (project, options); if (items.Length > 1) //FIXME: msbuild gives better errors throw new Exception (String.Format ("Exactly one item required, but got: {0}", items.Length)); if (items.Length == 0) return null; return items [0]; }
internal ITaskItem ConvertToITaskItem (Expression transform, ExpressionOptions options) { TaskItem taskItem; taskItem = new TaskItem (GetItemSpecFromTransform (transform, options), evaluatedMetadata); return taskItem; }
public string ConvertToString (Project project, ExpressionOptions options) { return ConvertResult (Invoke (project, options)); }
public override object Evaluate(ExpressionOptions options) { // Evaluate if required or if the expression is invalid if ((options & ExpressionOptions.EVALUATE_ALWAYS) > 0 || !IsValid) { int paramCount = _parameters.Length; object[] paramValues = new object[paramCount]; for (int i = 0; i < paramCount; i++) { paramValues[i] = _parameters[i].Evaluate(options); } _value = _func.Invoke(paramValues); IsValid = true; } return _value; }
// In eval phase, any ref'ed item would've already been expanded // or it doesnt exist, so dont expand again // In non-eval, items have _already_ been expanded, so dont expand again // So, ignore @options internal ITaskItem[] ConvertToITaskItemArray (Expression transform, Expression separator, ExpressionOptions options) { if (separator != null) // separator present, so return as a single "join'ed" string return new ITaskItem [] { new TaskItem (ConvertToString (transform, separator, options)) }; ITaskItem[] array = new ITaskItem [buildItems.Count]; int i = 0; foreach (BuildItem item in buildItems) array [i++] = item.ConvertToITaskItem (transform, ExpressionOptions.DoNotExpandItemRefs); return array; }
object ConvertToNonArray (Project project, Type type, ExpressionOptions options) { return ConvertToObject (ConvertToString (project, options), type, options); }
/// <summary> /// Preforms the post-parse procedure of the options. /// </summary> /// <param name="options">The raw options string to parse.</param> private void ParseOptions(string options) { if (options == null) { return; } var splittedOptions = options.Split(','); Options = new ExpressionOptions(); Options.AsKeyValue = new Dictionary<string,string>(splittedOptions.Length); foreach (var option in splittedOptions) { var keyValue = option.Split('='); Options.AsKeyValue.Add(keyValue[0].Trim(), keyValue.Length > 1? keyValue[1].Trim() : null); } Options.AsExpressions = new List<LatexExpression>(); string beginning = options; string end; LatexExpression expr; int index = 0; bool verbatimMode = false; bool whitespaceBefore = false; while ((expr = ReadFromTextReader(this, 0, ref index, ref verbatimMode, MathMode | ExprType == ExpressionType.InlineMath | ExprType == ExpressionType.BlockMath, Customization, beginning, null, out end, ref whitespaceBefore)) != null) { beginning = end; Options.AsExpressions.Add(expr); } }
public ITaskItem[] ConvertToITaskItemArray (Project project, ExpressionOptions options) { var items = new ITaskItem[1]; items[0] = new TaskItem (ConvertToString (project, options)); return items; }
public static object ParseExpression(string expressionText, ExpressionOptions options) { //Match match = _functionRegEx.Match(expressionText); Match match = _expressionRegEx.Match(expressionText); if (match != null) { return ParseExpression(match).Evaluate(options); } return null; }
public string ConvertToString (Project project, ExpressionOptions options) { return project.GetMetadataBatched (itemName, metadataName); }
// In eval phase, any ref'ed item would've already been expanded // or it doesnt exist, so dont expand again // In non-eval, items have _already_ been expanded, so dont expand again // So, ignore @options internal string ConvertToString (Expression transform, Expression separator, ExpressionOptions options) { string separatorString; // Item refs are not expanded for separator or transform if (separator == null) separatorString = ";"; else separatorString = (string) separator.ConvertTo (parentProject, typeof (string), ExpressionOptions.DoNotExpandItemRefs); string[] items = new string [buildItems.Count]; int i = 0; foreach (BuildItem bi in buildItems) items [i++] = bi.ConvertToString (transform, ExpressionOptions.DoNotExpandItemRefs); return String.Join (separatorString, items); }
void ExpandArguments (Project project, ExpressionOptions options) { for (int i = 0; i < Arguments.Count; ++i) { string arg = Arguments [i].Trim (); if (string.Equals (arg, "null", StringComparison.OrdinalIgnoreCase)) { arg = null; } else { arg = Expression.ParseAs<string> (arg, ParseOptions.None, project, options); arg = arg.Trim (ArgumentTrimChars); } Arguments [i] = arg; } }
public static string Parse(string line, ExpressionOptions options) { if (line.IndexOf("#(") > -1) { MatchCollection matches = _exprTriggerRegEx.Matches(line); int offset = 0; foreach (Match match in matches) { string result; try { result = ParseExpression(match).Evaluate(options).ToString(); } catch (TargetInvocationException ex) { result = ex.InnerException.ToString().Replace('\n', ' ').Replace('\r', ' '); } catch (Exception ex) { result = ex.ToString().Replace('\n', ' ').Replace('\r', ' '); } //line = line.Replace(match.Value, result); line = line.Remove(match.Index + offset, match.Length).Insert(match.Index + offset, result); offset += result.Length - match.Length; } } return line; }
public ITaskItem[] ConvertToITaskItemArray (Project project, ExpressionOptions options) { throw new NotImplementedException (); }
// during item's eval phase, any item refs in this item, have either // already been expanded or are non-existant, so expand can be _false_ // // during prop's eval phase, this isn't reached, as it parses expressions // with allowItems=false, so no ItemReferences are created at all // // at other times, item refs have already been expanded, so expand: false internal string ConvertToString (Expression transform, ExpressionOptions options) { return GetItemSpecFromTransform (transform, options); }
// during property's eval phase, this is never reached, as PropertyReference // handles the eval case // // during item's eval phase, we have expand: true, that's what we // do here.. // // during non-eval, expand: true // So, its always true here internal string ConvertToString (Project project, ExpressionOptions options) { if (converting) { // found ref to @this while trying to ConvertToString // for @this! return FinalValue; } converting = true; try { Expression exp = new Expression (); // in non-evaluation phase, properties are always expanded exp.Parse (FinalValue, options == ExpressionOptions.ExpandItemRefs ? ParseOptions.AllowItems : ParseOptions.None); return (string) exp.ConvertTo (project, typeof (string), options); } finally { converting = false; } }
string GetItemSpecFromTransform (Expression transform, ExpressionOptions options) { StringBuilder sb; if (transform == null) { if (options == ExpressionOptions.ExpandItemRefs) { // With usual code paths, this will never execute, // but letting this be here, incase BI.ConvertTo* // is called directly Expression expr = new Expression (); expr.Parse (finalItemSpec, ParseOptions.AllowItemsNoMetadataAndSplit); return (string) expr.ConvertTo (parent_item_group.ParentProject, typeof (string), ExpressionOptions.ExpandItemRefs); } else { return finalItemSpec; } } else { // Transform, _DONT_ expand itemrefs sb = new StringBuilder (); foreach (object o in transform.Collection) { if (o is string) { sb.Append ((string)o); } else if (o is PropertyReference) { sb.Append (((PropertyReference)o).ConvertToString ( parent_item_group.ParentProject, ExpressionOptions.DoNotExpandItemRefs)); } else if (o is ItemReference) { sb.Append (((ItemReference)o).ConvertToString ( parent_item_group.ParentProject, ExpressionOptions.DoNotExpandItemRefs)); } else if (o is MetadataReference) { sb.Append (GetMetadata (((MetadataReference)o).MetadataName)); } } return sb.ToString (); } }
object ConvertToArray (Project project, Type type, ExpressionOptions options) { ITaskItem[] items = ConvertToITaskItemArray (project, options); Type element_type = type.GetElementType (); Array arr = Array.CreateInstance (element_type, items.Length); for (int i = 0; i < arr.Length; i ++) arr.SetValue (ConvertToObject (items [i].ItemSpec, element_type, options), i); return arr; }
internal ITaskItem[] ConvertToITaskItemArray (Project project, ExpressionOptions options) { if (converting) { // found ref to @this while trying to ConvertToITaskItemArray // for @this! ITaskItem []items = new ITaskItem [1]; items [0] = new TaskItem (FinalValue); return items; } converting = true; try { Expression exp = new Expression (); // in non-evaluation phase, properties are always expanded exp.Parse (FinalValue, ParseOptions.Split | (options == ExpressionOptions.ExpandItemRefs ? ParseOptions.AllowItems : ParseOptions.None)); return (ITaskItem[]) exp.ConvertTo (project, typeof (ITaskItem[]), options); } finally { converting = false; } }
object ConvertToObject (string raw, Type type, ExpressionOptions options) { if (type == typeof (bool)) { bool value; if (boolValues.TryGetValue (raw, out value)) return value; else return false; } if (type == typeof (string)) return raw; if (type.IsPrimitive) return Convert.ChangeType (raw, type); if (type == typeof (DateTime)) return DateTime.Parse (raw); throw new Exception (String.Format ("Unsupported type: {0}", type)); }