Skip to content

Commit 754ddae

Browse files
committed
设置mysql驱动源
1 parent 200fe82 commit 754ddae

File tree

2 files changed

+50
-65
lines changed

2 files changed

+50
-65
lines changed

XCode.MySql/XCode.MySql.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@
3636
</None>
3737
</ItemGroup>
3838
<ItemGroup>
39-
<ProjectReference Include="..\XCode\XCode.csproj" />
39+
<PackageReference Include="MySql.Data" Version="9.5.0" />
4040
</ItemGroup>
4141
<ItemGroup>
42-
<!-- 按需求禁用 MySqlConnector:原先会导致同时下载并优先尝试使用 MySqlConnector 工厂
43-
<PackageReference Include="MySqlConnector" Version="2.4.0" />
44-
-->
42+
<ProjectReference Include="..\XCode\XCode.csproj" />
4543
</ItemGroup>
4644
</Project>
Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,59 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
using NewLife;
1+
namespace XCode.DataAccessLayer;
52

6-
namespace XCode.DataAccessLayer
3+
/// <summary>连接字符串构造器</summary>
4+
public class ConnectionStringBuilder(String connStr)
75
{
8-
/// <summary>连接字符串构造器</summary>
9-
public class ConnectionStringBuilder /*: Dictionary<String, String>*/
6+
#region 属性
7+
private readonly IDictionary<String, String> _dic = connStr.SplitAsDictionary("=", ";", true);
8+
9+
/// <summary>获取 或 设置 设置项</summary>
10+
/// <param name="key"></param>
11+
/// <returns></returns>
12+
public String this[String key] { get => _dic[key]; set => _dic[key] = value; }
13+
14+
/// <summary>连接字符串</summary>
15+
public String ConnectionString => _dic.Join(";", kv => $"{kv.Key}={kv.Value}");
16+
#endregion
17+
18+
#region 方法
19+
/// <summary>获取连接字符串中的项</summary>
20+
/// <param name="key"></param>
21+
/// <param name="value">数值</param>
22+
/// <returns></returns>
23+
public Boolean TryGetValue(String key, out String value) => _dic.TryGetValue(key, out value);
24+
25+
/// <summary>获取并删除连接字符串中的项</summary>
26+
/// <param name="key"></param>
27+
/// <param name="value">数值</param>
28+
/// <returns></returns>
29+
public Boolean TryGetAndRemove(String key, out String value)
1030
{
11-
#region 属性
12-
private readonly IDictionary<String, String> _dic;
31+
value = String.Empty;
1332

14-
/// <summary>获取 或 设置 设置项</summary>
15-
/// <param name="key"></param>
16-
/// <returns></returns>
17-
public String this[String key] { get => _dic?[key]; set => _dic[key] = value; }
18-
#endregion
33+
if (_dic == null || !_dic.TryGetValue(key, out value)) return false;
1934

20-
#region 构造
21-
/// <summary>实例化</summary>
22-
public ConnectionStringBuilder(String connStr) => _dic = connStr.SplitAsDictionary("=", ";", true);
23-
#endregion
35+
_dic.Remove(key);
2436

25-
#region 连接字符串
26-
/// <summary>连接字符串</summary>
27-
public String ConnectionString => _dic?.Join(";", kv => $"{kv.Key}={kv.Value}");
28-
#endregion
29-
30-
#region 方法
31-
/// <summary>获取连接字符串中的项</summary>
32-
/// <param name="key"></param>
33-
/// <param name="value">数值</param>
34-
/// <returns></returns>
35-
public Boolean TryGetValue(String key, out String value) => _dic.TryGetValue(key, out value);
36-
37-
/// <summary>获取并删除连接字符串中的项</summary>
38-
/// <param name="key"></param>
39-
/// <param name="value">数值</param>
40-
/// <returns></returns>
41-
public Boolean TryGetAndRemove(String key, out String value)
42-
{
43-
value = null;
44-
45-
if (_dic == null || !_dic.TryGetValue(key, out value)) return false;
46-
47-
_dic.Remove(key);
48-
49-
return true;
50-
}
51-
52-
/// <summary>尝试添加项,如果存在则失败</summary>
53-
/// <param name="key"></param>
54-
/// <param name="value"></param>
55-
/// <returns></returns>
56-
public Boolean TryAdd(String key,String value)
57-
{
58-
if (_dic.ContainsKey(key)) return false;
37+
return true;
38+
}
5939

60-
_dic[key] = value;
40+
/// <summary>尝试添加项,如果存在则失败</summary>
41+
/// <param name="key"></param>
42+
/// <param name="value"></param>
43+
/// <returns></returns>
44+
public Boolean TryAdd(String key, String value)
45+
{
46+
if (_dic.ContainsKey(key)) return false;
6147

62-
return true;
63-
}
64-
#endregion
48+
_dic[key] = value;
6549

66-
#region 辅助
67-
/// <summary>已重载。</summary>
68-
/// <returns></returns>
69-
public override String ToString() => ConnectionString;
70-
#endregion
50+
return true;
7151
}
52+
#endregion
53+
54+
#region 辅助
55+
/// <summary>已重载。</summary>
56+
/// <returns></returns>
57+
public override String ToString() => ConnectionString;
58+
#endregion
7259
}

0 commit comments

Comments
 (0)