コード例 #1
0
        public void AddNewContextCreationExpression(ParameterExpression contextParameter)
        {
            ConstructorInfo ctor = null;

            Type[]                   parameterTypes        = null;
            Expression               assignExpression      = null;
            NewExpression            newExpression         = null;
            IEnumerable <Expression> parametersExpressions = null;

            if (!_baseConstructorParameters.IsNullOrEmpty())
            {
                ParameterExpression parameter;
                List <Type>         types = new List <Type>();
                var parametersSet         = _baseConstructorParameters.ToDictionary(p => p.Name, p => p);

                parametersExpressions = Parameters.Select(p => {
                    Type type = p.Type;

                    if (parametersSet.TryGetValue(p.Name, out parameter))
                    {
                        type = parameter.Type.MakeByRefType();
                    }

                    types.Add(type);

                    return(p);
                }).ToList();

                if (parametersSet.TryGetValue("Uniquifier", out parameter))
                {
                    var expression = Expression.Default(parameter.Type);

                    types.Add(parameter.Type);
                    parametersExpressions = parametersExpressions.Concat(expression);
                }

                parameterTypes = types.ToArray();
            }
            else
            {
                var types = Parameters.Select(p => p.IsByRef ? p.Type.MakeByRefType() : p.Type);
                parameterTypes        = types.ToArray();
                parametersExpressions = Parameters;
            }

            ctor             = contextParameter.Type.GetConstructor(parameterTypes);
            newExpression    = Expression.New(ctor, parametersExpressions);
            assignExpression = Expression.Assign(contextParameter, newExpression);
            BlockExpressions.Insert(0, assignExpression);
        }
コード例 #2
0
        public ParameterExpression BuildVariable(Expression expr, string name = null)
        {
            if (name == null)
            {
                name = expr.Type.Name + Interlocked.Increment(ref VarIndex);
            }

            var variable = Expression.Variable(
                expr.Type,
                name.IndexOf('<') >= 0 ? null : name);

            BlockVariables.Add(variable);
            BlockExpressions.Add(Expression.Assign(variable, expr));

            return(variable);
        }
コード例 #3
0
        public Expression BuildBlock(Expression expression)
        {
#if FW4 || SILVERLIGHT
            if (IsBlockDisable || BlockExpressions.Count == 0)
            {
                return(expression);
            }

            BlockExpressions.Add(expression);

            expression = Expression.Block(BlockVariables, BlockExpressions);

            BlockVariables.Clear();
            BlockExpressions.Clear();
#endif

            return(expression);
        }
コード例 #4
0
        public Expression BuildBlock(Expression expression)
        {
            if (IsBlockDisable || BlockExpressions.Count == 0)
            {
                return(expression);
            }

            BlockExpressions.Add(expression);

            expression = Expression.Block(BlockVariables, BlockExpressions);

            while (BlockVariables.Count > 1)
            {
                BlockVariables.RemoveAt(BlockVariables.Count - 1);
            }
            while (BlockExpressions.Count > 1)
            {
                BlockExpressions.RemoveAt(BlockExpressions.Count - 1);
            }

            return(expression);
        }