Example #1
0
        public static async Task <ConvertResponse> ConvertAsync(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.ConvertAsync(codeWithOptions);

            return(new ConvertResponse(result.Success, result.ConvertedCode, result.GetExceptionsAsString()));
        }
Example #2
0
        public async Task <string> ConvertAsync(string code)
        {
            var options = new CodeWithOptions(code);
            var result  = await CodeConverter.ConvertAsync(options);

            return(result.ConvertedCode);
        }