/// <summary>
 /// Visits the children of the <see cref="System.Linq.Expressions.ElementInit"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
 protected override ElementInit VisitElementInit(ElementInit node)
 {
     // always part of IReadOnlyCollection<ElementInit>
     // a.Add(5, b)
     InvalidExpression(node.ToString());
     return(null);
 }
Exemplo n.º 2
0
 //
 // Summary:
 //     Visits the children of the System.Linq.Expressions.ElementInit.
 //
 // Parameters:
 //   node:
 //     The expression to visit.
 //
 // Returns:
 //     The modified expression, if it or any subexpression was modified; otherwise,
 //     returns the original expression.
 protected override ElementInit VisitElementInit(ElementInit node)
 {
     Console.WriteLine("VisitElementInit:");
     Console.WriteLine('\t' + node.GetType().ToString());
     Console.WriteLine('\t' + node.ToString());
     return(base.VisitElementInit(node));
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Loader.Load();
            Objects.LoadType(typeof(DynamicLinqTestObjects));

            var lines = new List <string>();

            foreach (var(key, filename) in rendererFileMapping.SelectKVP((k, v) => (k, v)))
            {
                var ordering = parseFileOrder(@$ "C:\Users\Spitz\source\repos\zspitz\ExpressionTreeToString\Tests\expectedResults\{filename}-testdata.txt");

                var language = key == VisualBasic ? Language.VisualBasic : Language.CSharp;
                //var language = key == CSharp ? Language.CSharp : Language.VisualBasic;

                const string dlinq   = nameof(DynamicLinqTestObjects);
                var          objects = Objects.Get()
                                       //.Where(x => key == DynamicLinq ? x.source == dlinq : x.source != dlinq)
                                       .Where(x => key == DynamicLinq)
                                       .Where(x => !ordering.ContainsKey($"{x.source}.{x.name}"));

                DynamicLinqWriterVisitor.CustomAccessibleTypes.Add(typeof(Console));
                DynamicLinqWriterVisitor.CustomAccessibleTypes.Add(typeof(Dummy));

                //var objects = Objects.Get()
                //    .Where(x => key == DynamicLinq ? x.source == dlinq : x.source != dlinq)
                //    .Where(x => key == DynamicLinq)
                //    .OrderBy(x => ordering.TryGetValue($"{x.source}.{x.name}", out var order) ? order : -1);

                foreach (var(category, source, name, o) in objects)
                {
                    var toWrite = o switch
                    {
                        Expression expr => expr.ToString(key, out var pathSpans, language),
                        MemberBinding mbind => mbind.ToString(key, out var pathSpans, language),
                        ElementInit init => init.ToString(key, out var pathSpans, language),
                        SwitchCase switchCase => switchCase.ToString(key, out var pathSpans, language),
                        CatchBlock catchBlock => catchBlock.ToString(key, out var pathSpans, language),
                        LabelTarget labelTarget => labelTarget.ToString(key, out var pathSpans, language),
                        _ => throw new NotImplementedException(),
                    };
                    lines.Add($"---- {source}.{name}");
                    if (key == FactoryMethods)
                    {
                        var toReplace =
                            language == Language.CSharp ?
                            @"// using static System.Linq.Expressions.Expression

" :
                            @"' Imports System.Linq.Expressions.Expression

";
                        toWrite = toWrite.Replace(toReplace, "");
                    }
                    lines.Add(toWrite);
                }

                lines.Add("------");
            }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Loader.Load();

            var lines = new List <string>();

            foreach (var(key, filename) in rendererFileMapping)
            {
                var ordering = parseFileOrder(@$ "C:\Users\Spitz\source\repos\zspitz\ExpressionTreeToString\Tests\expectedResults\{filename}-testdata.txt");

                var language = key == VisualBasic ? Language.VisualBasic : Language.CSharp;

                //foreach (var (category, source, name, o) in Objects.Get().OrderBy(x => ordering[$"{x.source}.{x.name}"])) {
                foreach (var(category, source, name, o) in Objects.Get().Where(x => !ordering.ContainsKey($"{x.source}.{x.name}")))
                {
                    lines.Add($"---- {source}.{name}");
                    var toWrite = o switch
                    {
                        Expression expr => expr.ToString(key, out var pathSpans, language),
                        MemberBinding mbind => mbind.ToString(key, out var pathSpans, language),
                        ElementInit init => init.ToString(key, out var pathSpans, language),
                        SwitchCase switchCase => switchCase.ToString(key, out var pathSpans, language),
                        CatchBlock catchBlock => catchBlock.ToString(key, out var pathSpans, language),
                        LabelTarget labelTarget => labelTarget.ToString(key, out var pathSpans, language),
                        _ => throw new NotImplementedException(),
                    };
                    if (key == FactoryMethods)
                    {
                        toWrite = toWrite.Replace(@"// using static System.Linq.Expressions.Expression

", "");
                    }
                    lines.Add(toWrite);
                }

                lines.Add("------");
            }
Exemplo n.º 5
0
 /// <summary>访问子内容为: <see cref="T:System.Linq.Expressions.ElementInit"></see>.</summary>
 /// <param name="node">被访问的表达式</param>
 /// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
 protected override ElementInit VisitElementInit(ElementInit node)
 {
     Log(node.ToString());
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
        public void ToStringShowsArguments()
        {
            ElementInit init = Expression.ElementInit(
                typeof(Dictionary <string, int>).GetMethod("Add"),
                Expression.Constant("Key"),
                Expression.Constant(42)
                );

            Assert.Equal(typeof(Dictionary <string, int>).GetMethod("Add").ToString() + "(\"Key\", 42)", init.ToString());
        }
 protected static void CannotOptimize(ElementInit init)
 {
     throw new QueryOptimizationException(init.ToString());
 }
Exemplo n.º 8
0
 private static void CannotConvertToSoda(ElementInit init)
 {
     throw new LinqQueryException(init.ToString());
 }