public static Expression Parameterize(Expression expression, out List <ParameterExpression> parameters, out List <object> values) { var p = new Parameterizer(); var result = p.Visit(expression); parameters = p.parameters; values = p.values; return(result); }
protected virtual Expression Parameterize(Expression expression) { if (_variableMap.Count > 0) { expression = VariableSubstitutor.Substitute(_variableMap, expression); } return(Parameterizer.Parameterize(expression)); }
private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer) { okayToDefer &= (receivingMember != null && policy.IsDeferLoaded(receivingMember)); // parameterize query projection = (ProjectionExpression)Parameterizer.Parameterize(projection); if (scope != null) { // also convert references to outer alias to named values! these become SQL parameters too projection = (ProjectionExpression)OuterParameterizer.Parameterize(scope.Alias, projection); } var saveScope = scope; ParameterExpression reader = Expression.Parameter(typeof(DbDataReader), "r" + nReaders++); scope = new Scope(scope, reader, projection.Source.Alias, projection.Source.Columns); LambdaExpression projector = Expression.Lambda(Visit(projection.Projector), reader); scope = saveScope; string commandText = policy.Mapping.Language.Format(projection.Source); ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(projection.Source); string[] names = namedValues.Select(v => v.Name).ToArray(); Expression[] values = namedValues.Select(v => Expression.Convert(Visit(v.Value), typeof(object))).ToArray(); string methExecute = okayToDefer ? "ExecuteDeferred" : "Execute"; if (okayToDefer) { } // call low-level execute directly on supplied DbQueryProvider Expression result = Expression.Call(provider, methExecute, new[] { projector.Body.Type }, Expression.New( typeof(QueryCommand <>).MakeGenericType(projector.Body.Type). GetConstructors()[0], Expression.Constant(commandText), Expression.Constant(names), projector ), Expression.NewArrayInit(typeof(object), values) ); if (projection.Aggregator != null) { // apply aggregator result = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], result); } return(result); }
void OnEnable() { _resolution = (int)resolution; _camera = GetComponent <Camera>(); _command = new CommandBuffer { name = "VXGI" }; _mipmapper = new Mipmapper(this); _parameterizer = new Parameterizer(); _voxelizer = new Voxelizer(this); _voxelShader = new VoxelShader(this); _lastVoxelSpaceCenter = voxelSpaceCenter; CreateBuffers(); CreateTextureDescriptor(); CreateTextures(); }
void OnEnable() { _resolution = (int)resolution; _camera = GetComponent <Camera>(); _command = new CommandBuffer { name = "VXGI.MonoBehaviour" }; _lights = new List <LightSource>(64); _lightSources = new ComputeBuffer(64, LightSource.size); _mipmapper = new Mipmapper(this); _parameterizer = new Parameterizer(); _voxelizer = new Voxelizer(this); _voxelShader = new VoxelShader(this); _lastVoxelSpaceCenter = voxelSpaceCenter; CreateBuffers(); CreateTextureDescriptor(); CreateTextures(); }
private LambdaExpression Parameterize(Expression query, out object[] arguments) { IQueryProvider provider = this.FindProvider(query); if (provider == null) { throw new ArgumentException(Res.ArgumentQuery); } var ep = provider as IDbContext; // turn all relatively constant expression into actual constants Func <Expression, bool> fnCanBeEvaluated = e => ep != null?ExpressionHelper.CanBeEvaluatedLocally(e) : true; var body = PartialEvaluator.Eval(query, fnCanBeEvaluated); // convert all constants into parameters List <ParameterExpression> parameters; List <object> values; body = Parameterizer.Parameterize(body, out parameters, out values); // make sure the body will return a value typed as 'object'. if (body.Type != typeof(object)) { body = Expression.Convert(body, typeof(object)); } // make a lambda expression with these parameters arguments = values.ToArray(); if (arguments.Length < 5) { return(Expression.Lambda(body, parameters.ToArray())); } else { // too many parameters, use an object array instead. arguments = new object[] { arguments }; return(ExplicitToObjectArray.Rewrite(body, parameters)); } }
/// <summary> /// Determine which sub-expressions must be parameters /// </summary> /// <param name="expression"></param> /// <returns></returns> public virtual Expression Parameterize(Expression expression) { return(Parameterizer.Parameterize(this.Language, expression)); }
/// <summary> /// Determine which sub-expressions must be parameters /// </summary> /// <param name="expression"></param> /// <returns></returns> public virtual Expression Parameterize(Expression expression) { return(Parameterizer.Parameterize(expression)); }
public MyVisitor() { _defaultVisitor = new Parameterizer(); }