/// <summary> /// 根据数据库提供程序名称获取 <see cref="NDF.Data.Common.DbScriptParameterParser"/> 对象,该对象可用于对 SQL 脚本中定义的参数列表进行解析。 /// </summary> /// <param name="providerName">数据库提供程序名称.</param> /// <returns>返回一个 <see cref="NDF.Data.Common.DbScriptParameterParser"/> 对象,该对象可用于对 SQL 脚本中定义的参数列表进行解析。</returns> public static DbScriptParameterParser GetScriptParameterParser(string providerName) { Check.NotEmpty(providerName, "providerName"); DbScriptParameterParser parser = null; lock (_locker) { if (!DbScriptParameterParserCache.TryGetValue(providerName, out parser)) { Type type = typeof(DbScriptParameterParser).GetSubClass().FirstOrDefault(t => { var attribute = t.GetCustomAttributes(typeof(DbProviderAttribute), true).OfType <DbProviderAttribute>().FirstOrDefault(); return(attribute != null && attribute.ProviderName == providerName); }); if (type == null) { if (!DbProviderFactoryExtensions.DbProviderFactoryClasses.Any(item => item.InvariantName == providerName)) { throw new InvalidOperationException(string.Format(Resources.NotExistsAllowedDbProviderAttributeDbScriptParameterParser, providerName)); } type = typeof(GenericScriptParameterParser); } parser = Activator.CreateInstance(type, providerName) as DbScriptParameterParser; DbScriptParameterParserCache.Add(providerName, parser); } } return(parser); }
/// <summary> /// 为 <see cref="System.Data.Common.DbProviderFactory"/> 实例提供一组工具方法扩展。 /// </summary> /// <param name="factory">表示一个 <see cref="System.Data.Common.DbProviderFactory"/> 对象。</param> /// <returns>返回一个 <see cref="NDF.Data.Common.DbScriptParameterParser"/> 对象,该对象可用于对 SQL 脚本中定义的参数列表进行解析。</returns> public static DbScriptParameterParser GetScriptParameterParser(this DbProviderFactory factory) { string providerName = GetProviderName(factory); return(DbScriptParameterParser.GetScriptParameterParser(providerName)); }