Exemple #1
0
        static async Task Main(string[] args)
        {
            MSBuildLocator.RegisterDefaults();

            var slnOrCsprojFile = args[0];
            var outputDir       = args[1];

            if (!Path.IsPathRooted(slnOrCsprojFile))
            {
                slnOrCsprojFile = Path.Combine(Environment.CurrentDirectory, slnOrCsprojFile);
            }

            if (!Path.IsPathRooted(outputDir))
            {
                outputDir = Path.Combine(Environment.CurrentDirectory, outputDir);
            }

            using (var workspace = MSBuildWorkspace.Create())
            {
                if (slnOrCsprojFile.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
                {
                    await SharpCompiler.CompileSolution(await workspace.OpenSolutionAsync(slnOrCsprojFile), outputDir);
                }
                else
                {
                    await SharpCompiler.CompileProject(await workspace.OpenProjectAsync(slnOrCsprojFile), outputDir);
                }
            }
        }
Exemple #2
0
        public async Task TestTransformCode()
        {
            var code = @"
    using System;

    namespace Test
    {
        public class MyClass
        {
            public string Name { get; set; }

            public int Count, VirtualTotal;

            public MyClass()
            {            
            }

            public void MyTestMethod(string categoryName, int itemCount)
            {
            }
        }
    }";

            var document = GetProjectDocumentForCode(code);
            var solution = document.Project.Solution;

            solution = await SharpTransformer.TransformSolution(solution);

            var ass = await SharpCompiler.CompileProject(solution.Projects.FirstOrDefault());

            var allTypes = ass.GetTypes();

            var myClassType = ass.GetType("Test.my_class");

            Assert.NotNull(myClassType);

            var testMethod = myClassType.GetMethod("my_test_method");

            Assert.NotNull(testMethod);

            var parameters = testMethod.GetParameters();

            Assert.Equal(2, parameters.Length);
            Assert.Equal("category_name", parameters[0].Name);
            Assert.Equal("item_count", parameters[1].Name);

            Assert.NotNull(myClassType.GetProperty("name"));

            Assert.NotNull(myClassType.GetField("count"));
            Assert.NotNull(myClassType.GetField("virtual_total"));
        }
Exemple #3
0
        public async Task TestTransformProject()
        {
            var workspace = MSBuildWorkspace.Create();
            var project   = await workspace.OpenProjectAsync(Path.Combine(AppContext.BaseDirectory, "../../../../TestAssembly/TestAssembly.csproj"));

            var ass = await SharpCompiler.CompileProject(project);

            Assert.NotNull(ass);
            Assert.Equal("TestAssembly.Py", ass.GetName().Name);

            var itemRecordType = ass.GetType("TestAssembly.item_record");

            Assert.NotNull(itemRecordType);

            Assert.NotNull(itemRecordType.GetProperty("name"));
            Assert.NotNull(itemRecordType.GetProperty("description"));
            Assert.NotNull(itemRecordType.GetProperty("current_ticks"));
        }