// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using Microsoft.AspNet.Razor.Chunks.Generators; using Microsoft.AspNet.Razor.CodeGeneration; using Microsoft.AspNet.Razor.Parser; namespace Microsoft.AspNet.Razor { /// /// Represents a code language in Razor. /// public abstract class RazorCodeLanguage { private static IDictionary _services = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "cshtml", new CSharpRazorCodeLanguage() } }; /// /// Gets the list of registered languages mapped to file extensions (without a ".") /// public static IDictionary Languages { get { return _services; } } /// /// The name of the language (for use in System.Web.Compilation.BuildProvider.GetDefaultCompilerTypeForLanguage) /// public abstract string LanguageName { get; } /// /// Gets the RazorCodeLanguage registered for the specified file extension /// /// The extension, with or without a "." /// The language registered for that extension public static RazorCodeLanguage GetLanguageByExtension(string fileExtension) { RazorCodeLanguage service = null; Languages.TryGetValue(fileExtension.TrimStart('.'), out service); return service; } /// /// Constructs the code parser. Must return a new instance on EVERY call to ensure thread-safety /// public abstract ParserBase CreateCodeParser(); /// /// Constructs the chunk generator. Must return a new instance on EVERY call to ensure thread-safety /// public abstract RazorChunkGenerator CreateChunkGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host); public abstract CodeGenerator CreateCodeGenerator(CodeGeneratorContext chunkGeneratorContext); } }