示例#1
0
        public static async Task <ConversionResult> Convert(CodeWithOptions code)
        {
            if (!IsSupportedSource(code.FromLanguage, code.FromLanguageVersion))
            {
                return(new ConversionResult(new NotSupportedException($"Source language {code.FromLanguage} {code.FromLanguageVersion} is not supported!")));
            }
            if (!IsSupportedTarget(code.ToLanguage, code.ToLanguageVersion))
            {
                return(new ConversionResult(new NotSupportedException($"Target language {code.ToLanguage} {code.ToLanguageVersion} is not supported!")));
            }
            if (code.FromLanguage == code.ToLanguage && code.FromLanguageVersion != code.ToLanguageVersion)
            {
                return(new ConversionResult(new NotSupportedException($"Converting from {code.FromLanguage} {code.FromLanguageVersion} to {code.ToLanguage} {code.ToLanguageVersion} is not supported!")));
            }

            switch (code.FromLanguage)
            {
            case "C#":
                switch (code.ToLanguage)
                {
                case "Visual Basic":
                    return(await ProjectConversion.ConvertText <CSToVBConversion>(code.Text, new TextConversionOptions(code.References)));
                }
                break;

            case "Visual Basic":
                switch (code.ToLanguage)
                {
                case "C#":
                    return(await ProjectConversion.ConvertText <VBToCSConversion>(code.Text, new TextConversionOptions(code.References)));
                }
                break;
            }
            return(new ConversionResult(new NotSupportedException($"Converting from {code.FromLanguage} {code.FromLanguageVersion} to {code.ToLanguage} {code.ToLanguageVersion} is not supported!")));
        }
示例#2
0
        public static ConversionResult Convert(CodeWithOptions code)
        {
            if (!IsSupportedSource(code.FromLanguage, code.FromLanguageVersion))
            {
                return(new ConversionResult(new NotSupportedException($"Source language {code.FromLanguage} {code.FromLanguageVersion} is not supported!")));
            }
            if (!IsSupportedTarget(code.ToLanguage, code.ToLanguageVersion))
            {
                return(new ConversionResult(new NotSupportedException($"Target language {code.ToLanguage} {code.ToLanguageVersion} is not supported!")));
            }
            if (code.FromLanguage == code.ToLanguage && code.FromLanguageVersion != code.ToLanguageVersion)
            {
                return(new ConversionResult(new NotSupportedException($"Converting from {code.FromLanguage} {code.FromLanguageVersion} to {code.ToLanguage} {code.ToLanguageVersion} is not supported!")));
            }

            switch (code.FromLanguage)
            {
            case "C#":
                switch (code.ToLanguage)
                {
                case "Visual Basic":
                    return(CSharpConverter.ConvertText(code.Text, code.References));
                }
                break;

            case "Visual Basic":
                switch (code.ToLanguage)
                {
                case "C#":
                    return(VisualBasicConverter.ConvertText(code.Text, code.References));
                }
                break;
            }
            return(new ConversionResult(new NotSupportedException($"Converting from {code.FromLanguage} {code.FromLanguageVersion} to {code.ToLanguage} {code.ToLanguageVersion} is not supported!")));
        }