public AverageAggregator(IAggregator sumAggregator, Expression <object> avgExpression, ParameterBinding sumParameter, ParameterBinding countParameter) { if (sumAggregator == null) { throw ExceptionBuilder.ArgumentNull("sumAggregator"); } if (avgExpression == null) { throw ExceptionBuilder.ArgumentNull("avgExpression"); } if (sumParameter == null) { throw ExceptionBuilder.ArgumentNull("sumParam"); } if (countParameter == null) { throw ExceptionBuilder.ArgumentNull("countParam"); } _sumAggregator = sumAggregator; _avgExpression = avgExpression; _returnType = avgExpression.Resolve(); _sumParameter = sumParameter; _countParameter = countParameter; }
public SumAggregator(Expression <object> addExpression, ParameterBinding leftParameter, ParameterBinding rightParameter, Expression <object> convertInputToSumExpression) { if (addExpression == null) { throw ExceptionBuilder.ArgumentNull("addExpr"); } if (leftParameter == null) { throw ExceptionBuilder.ArgumentNull("leftParam"); } if (rightParameter == null) { throw ExceptionBuilder.ArgumentNull("rightParam"); } if (convertInputToSumExpression == null) { throw ExceptionBuilder.ArgumentNull("convertInputToSumExpr)"); } _addExpression = addExpression; _returnType = addExpression.Resolve(); _leftParameter = leftParameter; _rightParameter = rightParameter; _convertInputToSumExpression = convertInputToSumExpression; }
public override IAggregator CreateAggregator(Type inputType) { if (inputType == null) { throw ExceptionBuilder.ArgumentNull("inputType"); } SumAggregateBinding sumAggregate = new SumAggregateBinding(String.Empty); IAggregator sumAggregator = sumAggregate.CreateAggregator(inputType); if (sumAggregator == null) { return(null); } Expression <object> avgExpression = new Expression <object>(); ParameterBinding sumParam = avgExpression.Parameters.Add("@Sum", sumAggregator.ReturnType); ParameterBinding countParam = avgExpression.Parameters.Add("@Count", typeof(int)); avgExpression.Text = "@Sum / @Count"; try { avgExpression.Resolve(); } catch (CompilationException) { return(null); } return(new AverageAggregator(sumAggregator, avgExpression, sumParam, countParam)); }
private static void EditParameter(ParameterBinding parameter) { using (EditParameterForm dlg = new EditParameterForm(false, parameter.Name, parameter.DataType, parameter.Value)) { if (dlg.ShowDialog() == DialogResult.OK) parameter.Value = dlg.ParameterValue; } }
private void NewParameter() { string parameterName = "Param" + (_evaluatable.Parameters.Count + 1); Type parameterType = typeof(string); string parameterValue = null; using (EditParameterForm dlg = new EditParameterForm(true, parameterName, parameterType, parameterValue)) { if (dlg.ShowDialog() == DialogResult.OK) { ParameterBinding newParameter = new ParameterBinding(dlg.ParameterName, dlg.ParameterType); newParameter.Value = dlg.ParameterValue; _evaluatable.Parameters.Add(newParameter); } } }
public SumAggregator(Expression<object> addExpression, ParameterBinding leftParameter, ParameterBinding rightParameter, Expression<object> convertInputToSumExpression) { if (addExpression == null) throw ExceptionBuilder.ArgumentNull("addExpr"); if (leftParameter == null) throw ExceptionBuilder.ArgumentNull("leftParam"); if (rightParameter == null) throw ExceptionBuilder.ArgumentNull("rightParam"); if (convertInputToSumExpression == null) throw ExceptionBuilder.ArgumentNull("convertInputToSumExpr)"); _addExpression = addExpression; _returnType = addExpression.Resolve(); _leftParameter = leftParameter; _rightParameter = rightParameter; _convertInputToSumExpression = convertInputToSumExpression; }
public AverageAggregator(IAggregator sumAggregator, Expression<object> avgExpression, ParameterBinding sumParameter, ParameterBinding countParameter) { if (sumAggregator == null) throw ExceptionBuilder.ArgumentNull("sumAggregator"); if (avgExpression == null) throw ExceptionBuilder.ArgumentNull("avgExpression"); if (sumParameter == null) throw ExceptionBuilder.ArgumentNull("sumParam"); if (countParameter == null) throw ExceptionBuilder.ArgumentNull("countParam"); _sumAggregator = sumAggregator; _avgExpression = avgExpression; _returnType = avgExpression.Resolve(); _sumParameter = sumParameter; _countParameter = countParameter; }
public void DictionaryProperties() { Query query = QueryFactory.CreateQuery(); query.Text = @" SELECT e.EmployeeID, e.FirstName, e.LastName FROM Employees e WHERE e.EmployeeID BETWEEN 1 AND 2 ORDER BY 1 "; Hashtable hashtable = new Hashtable(); hashtable["EmployeeID"] = -1; hashtable["FirstName"] = ""; hashtable["LastName"] = ""; ParameterBinding param = new ParameterBinding("@ROW", typeof (IDictionary), DictionaryPropertyProvider.GetProperties(hashtable)); Expression<object> expr = new Expression<object>(); expr.DataContext = query.DataContext; expr.Parameters.Add(param); DataTable dataTable = query.ExecuteDataTable(); foreach (DataRow row in dataTable.Rows) { Hashtable rowHashtable = new Hashtable(); param.Value = rowHashtable; foreach (DataColumn col in dataTable.Columns) rowHashtable[col.ColumnName] = row[col]; foreach (DataColumn col in dataTable.Columns) { expr.Text = "@ROW.[" + col.ColumnName + "]"; Assert.AreEqual(row[col], expr.Evaluate()); } } }
public void DataRowProperties() { Query query = QueryFactory.CreateQuery(); query.Text = @" SELECT e.EmployeeID, e.FirstName, e.LastName FROM Employees e WHERE e.EmployeeID BETWEEN 1 AND 2 ORDER BY 1 "; DataTable result = query.ExecuteDataTable(); Assert.AreEqual(2, result.Rows.Count); Expression<object> expr = new Expression<object>(); expr.DataContext = query.DataContext; ParameterBinding param = new ParameterBinding("@ROW", typeof (DataRow), DataRowPropertyProvider.GetProperties(result)); expr.Parameters.Add(param); param.Value = result.Rows[0]; expr.Text = "@ROW.EmployeeID"; Assert.AreEqual(1, expr.Evaluate()); expr.Text = "@ROW.FirstName"; Assert.AreEqual("Nancy", expr.Evaluate()); expr.Text = "@ROW.LastName"; Assert.AreEqual("Davolio", expr.Evaluate()); param.Value = result.Rows[1]; expr.Text = "@ROW.EmployeeID"; Assert.AreEqual(2, expr.Evaluate()); expr.Text = "@ROW.FirstName"; Assert.AreEqual("Andrew", expr.Evaluate()); expr.Text = "@ROW.LastName"; Assert.AreEqual("Fuller", expr.Evaluate()); }
public void AcceptParameter(ParameterBinding parameter) { Add("@" + parameter.Name, parameter.GetFullName(), parameter.DataType.Name, PARAMETER_IMG_INDEX); Add(parameter.Name, parameter.GetFullName(), parameter.DataType.Name, PARAMETER_IMG_INDEX); }
void IErrorReporter.AmbiguousParameter(SourceRange sourceRange, Identifier identifier, ParameterBinding[] candidates) { string message = String.Format(CultureInfo.CurrentCulture, Resources.AmbiguousParameter, identifier, FormattingHelpers.FormatBindingList(candidates)); HandleError(sourceRange, ErrorId.AmbiguousParameter, message); }
public MyFunctionParameter(ParameterBinding parameter) { _parameter = parameter; }
public override IAggregator CreateAggregator(Type inputType) { if (inputType == null) { throw ExceptionBuilder.ArgumentNull("inputType"); } // Create an expression to determine the type of inputType + inputType Expression <object> addExpr = new Expression <object>(); addExpr.Parameters.Add("@Left", inputType); addExpr.Parameters.Add("@Right", inputType); addExpr.Text = "@Left + @Right"; Type sumType; try { sumType = addExpr.Resolve(); } catch (CompilationException) { return(null); } // Now change the type of the first argument to the result type of 'inputType + inputType' addExpr.Parameters.Clear(); ParameterBinding leftParam = addExpr.Parameters.Add("@Left", sumType); ParameterBinding rightParam = addExpr.Parameters.Add("@Right", inputType); addExpr.Text = "@Left + @Right"; try { Type newSumType = addExpr.Resolve(); if (newSumType != sumType) { return(null); } } catch (CompilationException) { return(null); } // Conversion from inputType to sumType Expression <object> convertInputToSumExpr = new Expression <object>(); convertInputToSumExpr.Parameters.Add("@Input", inputType); convertInputToSumExpr.Text = "@Input"; convertInputToSumExpr.TargetType = sumType; try { convertInputToSumExpr.Resolve(); } catch (CompilationException) { return(null); } return(new SumAggregator(addExpr, leftParam, rightParam, convertInputToSumExpr)); }
public void AcceptParameter(ParameterBinding parameter) { }