コード例 #1
0
        public override IDbConnection CreateMsSqlConnection(string connectionString)
        {
            if (MsSqlFunc == null)
            {
                lock (SyncObj)
                {
                    if (MsSqlFunc == null)
                    {
                        var type = Type.GetType("System.Data.SqlClient.SqlConnection,System.Data.SqlClient");
                        AssertUtils.IsNotNull(type, "请添加System.Data.SqlClient组件");
                        MsSqlFunc = MethodUtils.CreateInstanceDelegate <Func <string, IDbConnection> >(type, new Type[] { typeof(string) });
                    }
                }
            }

            return(MsSqlFunc(connectionString));
        }
コード例 #2
0
        public override IDbConnection CreateMySqlConnection(string connectionString)
        {
            if (MySqlFunc == null)
            {
                lock (SyncObj)
                {
                    if (MySqlFunc == null)
                    {
                        var type = Type.GetType("MySql.Data.MySqlClient.MySqlConnection,MySql.Data");
                        AssertUtils.IsNotNull(type, "请添加MySql.Data组件");
                        var MySqlConstructor = type.GetConstructor(new Type[] { typeof(string) });
                        // Activator.CreateInstance
                        // return MySqlCons tructor.Invoke(new object[] { connectionString }) as IDbConnection;
                        MySqlFunc = MethodUtils.CreateInstanceDelegate <Func <string, IDbConnection> >(type, new Type[] { typeof(string) });
                    }
                }
            }

            return(MySqlFunc(connectionString));
        }