// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
namespace System.Web.Razor
{
///
/// Represents a code language in Razor.
///
public abstract class RazorCodeLanguage
{
private static IDictionary _services = new Dictionary(StringComparer.OrdinalIgnoreCase)
{
{ "cshtml", new CSharpRazorCodeLanguage() },
{ "vbhtml", new VBRazorCodeLanguage() }
};
///
/// 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; }
///
/// The type of the CodeDOM provider for this language
///
public abstract Type CodeDomProviderType { 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 code generator. Must return a new instance on EVERY call to ensure thread-safety
///
public abstract RazorCodeGenerator CreateCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host);
}
}