GetLanguageByExtension() public static method

Gets the RazorCodeLanguage registered for the specified file extension
public static GetLanguageByExtension ( string fileExtension ) : RazorCodeLanguage
fileExtension string The extension, with or without a "."
return RazorCodeLanguage
Example #1
0
        internal static void WriteGeneratedCode(string sourceFile, CodeCompileUnit codeCompileUnit)
        {
            if (!OutputDebuggingEnabled)
            {
                return;
            }

            RunTask(() =>
            {
                string extension           = Path.GetExtension(sourceFile);
                RazorCodeLanguage language = RazorCodeLanguage.GetLanguageByExtension(extension);
                CodeDomProvider provider   = CodeDomProvider.CreateProvider(language.LanguageName);

                using (var writer = new StringWriter())
                {
                    // Trim the html part of cshtml
                    string outputExtension = extension.Substring(0, 3);
                    string outputFileName  = Normalize(sourceFile) + "_generated" + outputExtension;
                    string outputPath      = Path.Combine(Path.GetDirectoryName(sourceFile), outputFileName);

                    // REVIEW: Do these options need to be tweaked?
                    provider.GenerateCodeFromCompileUnit(codeCompileUnit, writer, new CodeGeneratorOptions());
                    File.WriteAllText(outputPath, writer.ToString());
                }
            });
        }