private void AddNewProviderRegistration <T>(T provider) { Type providerType = provider.GetType(); if (providerType == typeof(IDataProvider)) { if (DataProvider != null) { throw new DataProviderAlreadySet(); } DataProvider = (IDataProvider)provider; Logger.Info($"Set Data Provider To {providerType.Name}."); return; } if (providerType == typeof(IAuthenticationProvider)) { if (AuthenticationProvider != null) { throw new AuthenticationProviderAlreadySet(); } AuthenticationProvider = (IAuthenticationProvider)provider; Logger.Info($"Set Authentication Provider To {providerType.Name}."); return; } if (Providers.ContainsKey(providerType)) { throw new ProviderWithTypeAlreadyRegistered(); } Providers.Add(providerType, (IProvider)provider); Logger.Info($"Registered Provider: {providerType.Name}."); }
internal static HTMLProvider GetProvider(Type T) { T = T ?? typeof(NullReference); if (Providers.ContainsKey(T)) { return(Providers[T]); } if (T.IsGenericType && Providers.ContainsKey(T.GetGenericTypeDefinition())) { return(Providers[T.GetGenericTypeDefinition()]); } Type parent = T.BaseType ?? typeof(object); while (!Providers.ContainsKey(parent)) { if (parent.IsGenericType && Providers.ContainsKey(parent.GetGenericTypeDefinition())) { return(Providers[parent.GetGenericTypeDefinition()]); } parent = parent.BaseType; } if (parent == typeof(object)) { foreach (Type i in T.GetInterfaces()) { if (Providers.ContainsKey(i)) { return(Providers[i]); } } } return(Providers[parent]); }
public static DbProvider GetProvider(string name) { if (Providers.ContainsKey(name)) { return(Providers[name]); } return(null); }
public static void SetProvider(ContainerBuilder builder, string providerType) { if (!Providers.ContainsKey(providerType)) { throw new ArgumentException("Invalid data provider type."); } Providers[providerType](builder); }
/// <summary> /// Creates a new instance of the <see cref="ISqlProvider"/> for the /// specified <paramref name="providerName"/>. /// </summary> /// <param name="providerName">The invariant provider name (e.g. "System.Data.SqlClient").</param> /// <returns>The SQL provider.</returns> public ISqlProvider GetProvider(string providerInvariantName) { if (Providers.ContainsKey(providerInvariantName)) { return(Activator.CreateInstance(Providers[providerInvariantName]) as ISqlProvider); } return(null); }
/// <summary> /// 转换字符串 /// </summary> /// <param name="input">输入</param> /// <returns>输出</returns> public static string Parse(this string input) { if (Providers.ContainsKey(CurrentUICulture.Name)) { return(Providers[CurrentUICulture.Name].Parse(input)); } var provider = new XmlLocalizationProvider(CurrentUICulture); Providers.Add(CurrentUICulture.Name, provider); return(provider.Parse(input)); }
/// <summary> /// Registers a new provider of the specified <paramref name="providerType"/>. /// </summary> /// <param name="providerType">Type of the provider.</param> public void RegisterProvider(Type providerType) { if (IsProvider(providerType)) { foreach (var attr in providerType.GetCustomAttributes(typeof(SqlProviderAttribute), false).Cast <SqlProviderAttribute>()) { if (!Providers.ContainsKey(attr.ProviderInvariantName)) { Providers.Add(attr.ProviderInvariantName, providerType); } } } }
public bool UnloadModule(string name) { if (!Providers.ContainsKey(name)) { return(false); } if (Providers[name].State != ProviderState.Loaded) { return(false); } Providers[name].State = ProviderState.Unloaded; return(true); }
/// <summary> /// Adds resource provider to the store, that is used to retrieve resource localizations. /// </summary> /// <param name="provider">The localizable resource provider.</param> public void AddResourceProvider(ILocalizableResourceProvider <TResourceKey, TResourceValue> provider) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } var culture = provider.GetCulture(); if (culture == null) { throw new InvalidOperationException("Culture could not be retrieved from provider."); } if (Providers.ContainsKey(culture)) { throw new InvalidOperationException($"Provider with culture \"{culture.Name}\" was already added."); } Providers.TryAdd(culture, provider); }