Esempio n. 1
0
        private static async Task Run()
        {
            MSBuildLocator.RegisterDefaults();
            var srcPath = @"/Users/rogerjohansson/RiderProjects/ConsoleApp4/ConsoleApp4.sln";


            var ws = MSBuildWorkspace.Create();

            ws.WorkspaceFailed += (sender, args) =>
            {
                Console.WriteLine("Workspace failed");
            };

            var output = @"/demooutput";
            var sln    = await ws.OpenSolutionAsync(srcPath);

            Console.WriteLine(sln.Version);

            foreach (var p in sln.Projects)
            {
                Console.WriteLine($"Project {p.Name}");
                foreach (var d in p.Documents)
                {
                    var n = d.Name.ToLowerInvariant();
                    Console.WriteLine($"Document {n}");
                    if (n.Contains("assemblyinfo") || n.Contains("assemblyattributes") || !n.EndsWith(".cs"))
                    {
                        continue;
                    }

                    var model = await d.GetSemanticModelAsync();

                    var root = await d.GetSyntaxRootAsync();

                    var visitor = new KotlinTranspilerVisitor(model);
                    var res     = visitor.Run(root);

                    var o        = d.FilePath.Replace("democode", "demooutput");
                    var fileName = Path.ChangeExtension(o, ".kt");
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));

                    var outputFile = Path.Combine(output, fileName);
                    File.WriteAllText(outputFile, res);
                    //   return;
                }
            }
        }
Esempio n. 2
0
        private static async Task Run()
        {
            var myPath = Assembly.GetExecutingAssembly().Location;

            var dir     = Path.GetDirectoryName(myPath);
            var srcPath = Path.GetFullPath(Path.Combine(dir, @"..\..\.."));

            var ws     = MSBuildWorkspace.Create();
            var output = srcPath + @"\demooutput";
            var sln    = await ws.OpenSolutionAsync(srcPath + @"\democode\DemoCode.sln");

            foreach (var p in sln.Projects)
            {
                foreach (var d in p.Documents)
                {
                    var n = d.Name.ToLowerInvariant();
                    if (n.Contains("assemblyinfo") || n.Contains("assemblyattributes") || !n.EndsWith(".cs"))
                    {
                        continue;
                    }

                    var model = await d.GetSemanticModelAsync();

                    var root = await d.GetSyntaxRootAsync();

                    var visitor = new KotlinTranspilerVisitor(model);
                    var res     = visitor.Run(root);

                    var o        = d.FilePath.Replace("democode", "demooutput");
                    var fileName = Path.ChangeExtension(o, ".kt");
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));

                    var outputFile = Path.Combine(output, fileName);
                    File.WriteAllText(outputFile, res);
                    //   return;
                }
            }
        }
Esempio n. 3
0
        private static async Task Run()
        {
            var ws = MSBuildWorkspace.Create();
            //     ws.WorkspaceFailed += Ws_WorkspaceFailed;
            var sln = await ws.OpenSolutionAsync(@"C:\Users\rojo01\Documents\Visual Studio 2017\Projects\Proto.Mailbox\Proto.Mailbox.sln");

            foreach (var p in sln.Projects)
            {
                foreach (var d in p.Documents)
                {
                    var n = d.Name.ToLowerInvariant();
                    if (n.Contains("assemblyinfo") || n.Contains("assemblyattributes") || !n.EndsWith(".cs"))
                    {
                        continue;
                    }
                    var model = await d.GetSemanticModelAsync();

                    var root = await d.GetSyntaxRootAsync();

                    var visitor = new KotlinTranspilerVisitor(model);
                    visitor.Visit(root);
                }
            }
        }
        public override void VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            var methodName         = node.Name.ToString();
            var sym                = _model.GetSymbolInfo(node).Symbol;
            var containingTypeName = sym?.ContainingType?.Name;

            switch (containingTypeName)
            {
            case nameof(Enumerable):
                switch (methodName)
                {
                case nameof(Enumerable.Select):
                    Visit(node.Expression);
                    Write(".");
                    Write("map");
                    break;

                case nameof(Enumerable.Where):
                    Visit(node.Expression);
                    Write(".");
                    Write("filter");
                    break;

                case nameof(Enumerable.ToList):
                    Visit(node.Expression);
                    Write(".");
                    Write("toList");
                    break;

                default:
                    break;
                }
                break;

            case nameof(Console):
                switch (methodName)
                {
                case nameof(Console.WriteLine):
                    Write("println");
                    break;

                case nameof(Console.Write):
                    Write("print");
                    break;

                case nameof(Console.ReadLine):
                    Write("readLine");
                    break;
                }
                break;

            default:
                Visit(node.Expression);
                Write(".");
                var name = node.Name.ToString();
                name = KotlinTranspilerVisitor.ToCamelCase(name);
                Write(name);
                break;
            }

            //  base.VisitMemberAccessExpression(node);
        }