Ejemplo n.º 1
0
        private static bool TryGetEnumerableExpression(object value, out Expression expression)
        {
            expression = null;
            IEnumerable enumerable = value as IEnumerable;

            if (enumerable != null)
            {
                foreach (object item in enumerable)
                {
                    if (expression == null)
                    {
                        expression = new Expression()
                        {
                            ObjectInitializerExpression = CodeGenerationTreeBuilder.CreateExpression(
                                typeof(Collection <>).MakeGenericType(item.GetType()))
                        };
                    }

                    expression.ObjectInitializerExpression.Elements.Add(new List <Expression>()
                    {
                        GetExpression(item)
                    });
                }
            }

            return(enumerable != null);
        }
Ejemplo n.º 2
0
        private static Expression GetStringConstantExpression(object value)
        {
            string text = value as string;

            return(text == null ? null : CodeGenerationTreeBuilder.CreateExpression(text));
        }