public LanguageContext GetLanguageByTypeName(string providerAssemblyQualifiedTypeName) { ContractUtils.RequiresNotNull(providerAssemblyQualifiedTypeName, nameof(providerAssemblyQualifiedTypeName)); var aqtn = AssemblyQualifiedTypeName.ParseArgument(providerAssemblyQualifiedTypeName, nameof(providerAssemblyQualifiedTypeName)); if (!Configuration.TryLoadLanguage(this, aqtn, out LanguageContext language)) { throw Error.UnknownLanguageProviderType(); } return(language); }
internal void AddLanguage(string languageTypeName, string displayName, IList <string> names, IList <string> fileExtensions, IDictionary <string, object> options, string paramName) { ContractUtils.Requires(!_frozen, "Configuration cannot be modified once the runtime is initialized"); ContractUtils.Requires( names.TrueForAll((id) => !String.IsNullOrEmpty(id) && !_languageNames.ContainsKey(id)), paramName ?? "names", "Language name should not be null, empty or duplicated between languages" ); ContractUtils.Requires( fileExtensions.TrueForAll((ext) => !String.IsNullOrEmpty(ext) && !_languageExtensions.ContainsKey(ext)), paramName ?? "fileExtensions", "File extension should not be null, empty or duplicated between languages" ); ContractUtils.RequiresNotNull(displayName, paramName ?? "displayName"); if (string.IsNullOrEmpty(displayName)) { ContractUtils.Requires(names.Count > 0, paramName ?? "displayName", "Must have a non-empty display name or a a non-empty list of language names"); displayName = names[0]; } var aqtn = AssemblyQualifiedTypeName.ParseArgument(languageTypeName, paramName ?? "languageTypeName"); if (_languageConfigurations.ContainsKey(aqtn)) { throw new ArgumentException(string.Format("Duplicate language with type name '{0}'", aqtn), "languageTypeName"); } // Add global language options first, they can be rewritten by language specific ones: var mergedOptions = new Dictionary <string, object>(_options); // Replace global options with language-specific options foreach (var option in options) { mergedOptions[option.Key] = option.Value; } var config = new LanguageConfiguration(aqtn, displayName, mergedOptions); _languageConfigurations.Add(aqtn, config); // allow duplicate ids in identifiers and extensions lists: foreach (var name in names) { _languageNames[name] = config; } foreach (var ext in fileExtensions) { _languageExtensions[NormalizeExtension(ext)] = config; } }