public async Task <string> ConvertAsync(string code)
        {
            var options = new CodeWithOptions(code);
            var result  = await CodeConverter.Convert(options);

            return(result.ConvertedCode);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Post([FromBody] ConvertRequest todo)
        {
            var languages = todo.requestedConversion.Split('2');

            string fromLanguage = "C#";
            string toLanguage   = "Visual Basic";
            int    fromVersion  = 6;
            int    toVersion    = 14;

            if (languages.Length == 2)
            {
                fromLanguage = ParseLanguage(languages[0]);
                fromVersion  = GetDefaultVersionForLanguage(languages[0]);
                toLanguage   = ParseLanguage(languages[1]);
                toVersion    = GetDefaultVersionForLanguage(languages[1]);
            }

            var codeWithOptions = new CodeWithOptions(todo.code)
                                  .WithDefaultReferences()
                                  .SetFromLanguage(fromLanguage, fromVersion)
                                  .SetToLanguage(toLanguage, toVersion);
            var result = CodeConverter.Convert(codeWithOptions);

            var response = new ConvertResponse()
            {
                conversionOk  = result.Success,
                convertedCode = result.ConvertedCode,
                errorMessage  = result.GetExceptionsAsString()
            };

            return(Ok(response));
        }
        public async Task NSwagStudio_Generate_Code_Using_NSwagStudio()
        {
            var contents = await NSwagStudioFileHelper.CreateNSwagStudioFileAsync(
                File.ReadAllText("Swagger.json"),
                "https://petstore.swagger.io/v2/swagger.json");

            File.WriteAllText("Petstore.nswag", contents);
            new NSwagStudioCodeGenerator(Path.GetFullPath("Petstore.nswag"), options)
            .GenerateCode(new Mock <IProgressReporter>().Object)
            .Should()
            .BeNull();

            var outputFile = Path.GetFullPath("PetstoreClient.cs");

            File.Exists(outputFile)
            .Should()
            .BeTrue();

            var csharp = File.ReadAllText(outputFile);
            var result = await CodeConverter.Convert(new CodeWithOptions(csharp));

            result.ConvertedCode
            .Should()
            .NotBeNullOrWhiteSpace();
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] ConvertRequest todo)
        {
            var languages = todo.requestedConversion.Split('2');

            string fromLanguage = LanguageNames.CSharp;
            string toLanguage   = LanguageNames.VisualBasic;
            int    fromVersion  = 6;
            int    toVersion    = 14;

            if (languages.Length == 2)
            {
                fromLanguage = ParseLanguage(languages[0]);
                fromVersion  = GetDefaultVersionForLanguage(languages[0]);
                toLanguage   = ParseLanguage(languages[1]);
                toVersion    = GetDefaultVersionForLanguage(languages[1]);
            }

            var codeWithOptions = new CodeWithOptions(todo.code)
                                  .WithTypeReferences(DefaultReferences.NetStandard2)
                                  .SetFromLanguage(fromLanguage, fromVersion)
                                  .SetToLanguage(toLanguage, toVersion);
            var result = await CodeConverter.Convert(codeWithOptions);

            var response = new ConvertResponse()
            {
                conversionOk  = result.Success,
                convertedCode = result.ConvertedCode,
                errorMessage  = result.GetExceptionsAsString()
            };

            return(Ok(response));
        }
Ejemplo n.º 5
0
        static ConversionResult TryConvertingCSToVBCode(string inputCode)
        {
            var codeWithOptions = new CodeWithOptions(inputCode)
                                  .SetFromLanguage("C#")
                                  .SetToLanguage("Visual Basic")
                                  .WithDefaultReferences();

            return(CodeConverter.Convert(codeWithOptions));
        }
Ejemplo n.º 6
0
        public static async Task InitAsync(TestContext testContext)
        {
            var codeGenerator = new NSwagCSharpCodeGenerator(
                Path.GetFullPath("Swagger.json"),
                typeof(NSwagVisualBasicCodeGeneratorTests).Namespace,
                optionsMock.Object);

            var options = new CodeWithOptions(codeGenerator.GenerateCode(mock.Object));
            var result  = await CodeConverter.Convert(options);

            code = result.ConvertedCode;
        }
Ejemplo n.º 7
0
        // [ClassInitialize]
        public static void Init(/* TestContext testContext */)
        {
            var codeGenerator = new AutoRestCSharpCodeGenerator(
                Path.GetFullPath("Swagger.json"),
                typeof(AutoRestVisualBasicCodeGeneratorTests).Namespace);

            var options = new CodeWithOptions(codeGenerator.GenerateCode(mock.Object));
            var result  = CodeConverter
                          .Convert(options)
                          .GetAwaiter()
                          .GetResult();

            code = result.ConvertedCode;
        }
Ejemplo n.º 8
0
        // [ClassInitialize]
        public static async Task InitAsync(/* TestContext testContext */)
        {
            optionsMock = new Mock <IGeneralOptions>();
            optionsMock.Setup(c => c.NSwagPath).Returns(PathProvider.GetJavaPath());

            var codeGenerator = new OpenApiCSharpCodeGenerator(
                Path.GetFullPath(SwaggerJsonFilename),
                "GeneratedCode",
                optionsMock.Object);

            var options = new CodeWithOptions(codeGenerator.GenerateCode(mock.Object));
            var result  = await CodeConverter.Convert(options);

            code = result.ConvertedCode;
        }
Ejemplo n.º 9
0
        public static async Task InitAsync(TestContext testContext)
        {
            optionsMock = new Mock <IGeneralOptions>();
            optionsMock.Setup(c => c.NSwagPath).Returns(PathProvider.GetJavaPath());

            var codeGenerator = new OpenApiCSharpCodeGenerator(
                Path.GetFullPath("Swagger.json"),
                typeof(OpenApiVisualBasicCodeGeneratorTests).Namespace,
                optionsMock.Object);

            var options = new CodeWithOptions(codeGenerator.GenerateCode(mock.Object));
            var result  = await CodeConverter.Convert(options);

            code = result.ConvertedCode;
        }
        // [ClassInitialize]
        public static async Task InitAsync(/* TestContext testContext */)
        {
            var defaultNamespace = typeof(NSwagVisualBasicCodeGeneratorTests).Namespace;
            var codeGenerator    = new NSwagCSharpCodeGenerator(
                Path.GetFullPath(SwaggerJsonFilename),
                defaultNamespace,
                optionsMock.Object,
                new OpenApiDocumentFactory(),
                new NSwagCodeGeneratorSettingsFactory(defaultNamespace, optionsMock.Object));

            var options = new CodeWithOptions(codeGenerator.GenerateCode(mock.Object));
            var result  = await CodeConverter.Convert(options);

            code = result.ConvertedCode;
        }
Ejemplo n.º 11
0
        static bool TryConvertingCSToVBCode(string csCode, out string vbCode)
        {
            vbCode = null;

            var codeWithOptions = new CodeWithOptions(csCode)
                                  .WithDefaultReferences();
            var result = CodeConverter.Convert(codeWithOptions);

            if (result.Success)
            {
                vbCode = result.ConvertedCode;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var result = CodeConverter.Convert(
                new CodeWithOptions(Console.In.ReadToEnd())
                .WithDefaultReferences()
                .SetFromLanguage("Visual Basic", 14)
                .SetToLanguage("C#", 6));

            if (result.Success)
            {
                Console.WriteLine(result.ConvertedCode);
            }
            else
            {
                Console.Error.WriteLine("Error:");
                Console.Error.WriteLine(result.GetExceptionsAsString());
            }
        }
Ejemplo n.º 13
0
    private static ConversionResult VB2CS(string vbCode)
    {
        var codeWithOptions = new CodeWithOptions(vbCode).SetFromLanguage("Visual Basic", 14).SetToLanguage("C#", 6);

        return(CodeConverter.Convert(codeWithOptions));
    }
Ejemplo n.º 14
0
    private static ConversionResult CS2VB(string cSharpCode)
    {
        var codeWithOptions = new CodeWithOptions(cSharpCode);

        return(CodeConverter.Convert(codeWithOptions));
    }