Skip to content

Commit fa8dad8

Browse files
committed
Connection
1 parent 091294a commit fa8dad8

10 files changed

Lines changed: 1204 additions & 1245 deletions

File tree

Src/Core/EConvertType.cs

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace WSharp.Core
1313
public static partial class EConvertType
1414
{
1515

16-
/// <summary>
17-
/// 转换为字节数组
16+
/// <summary> 转换为字节数组
1817
/// </summary>
1918
/// <param name="value"></param>
2019
/// <returns>字节数组</returns>
@@ -23,8 +22,7 @@ public static byte[] GetBytes(this short value)
2322
return BitConverter.GetBytes(value);
2423
}
2524

26-
/// <summary>
27-
/// 由字节数组中指定的位置转换
25+
/// <summary> 由字节数组中指定的位置转换
2826
/// </summary>
2927
/// <param name="bytes">字节数组</param>
3028
/// <param name="startIndex">开始的位置</param>
@@ -35,8 +33,7 @@ public static short ToShort(this byte[] bytes, int startIndex = 0)
3533
}
3634

3735

38-
/// <summary>
39-
/// 转换为字节数组
36+
/// <summary> 转换为字节数组
4037
/// </summary>
4138
/// <param name="value"></param>
4239
/// <returns>字节数组</returns>
@@ -45,8 +42,7 @@ public static byte[] GetBytes(this int value)
4542
return BitConverter.GetBytes(value);
4643
}
4744

48-
/// <summary>
49-
/// 由字节数组中指定的位置转换
45+
/// <summary> 由字节数组中指定的位置转换
5046
/// </summary>
5147
/// <param name="bytes">字节数组</param>
5248
/// <param name="startIndex">开始的位置</param>
@@ -57,8 +53,7 @@ public static int ToInt(this byte[] bytes, int startIndex = 0)
5753
}
5854

5955

60-
/// <summary>
61-
/// 转换为字节数组
56+
/// <summary> 转换为字节数组
6257
/// </summary>
6358
/// <param name="value"></param>
6459
/// <returns>字节数组</returns>
@@ -67,8 +62,7 @@ public static byte[] GetBytes(this long value)
6762
return BitConverter.GetBytes(value);
6863
}
6964

70-
/// <summary>
71-
/// 由字节数组中指定的位置转换
65+
/// <summary> 由字节数组中指定的位置转换
7266
/// </summary>
7367
/// <param name="bytes">字节数组</param>
7468
/// <param name="startIndex">开始的位置</param>
@@ -79,8 +73,7 @@ public static long ToLong(this byte[] bytes, int startIndex = 0)
7973
}
8074

8175

82-
/// <summary>
83-
/// 转换为字节数组
76+
/// <summary> 转换为字节数组
8477
/// </summary>
8578
/// <param name="value"></param>
8679
/// <returns>字节数组</returns>
@@ -89,8 +82,7 @@ public static byte[] GetBytes(this ushort value)
8982
return BitConverter.GetBytes(value);
9083
}
9184

92-
/// <summary>
93-
/// 由字节数组中指定的位置转换
85+
/// <summary> 由字节数组中指定的位置转换
9486
/// </summary>
9587
/// <param name="bytes">字节数组</param>
9688
/// <param name="startIndex">开始的位置</param>
@@ -101,8 +93,7 @@ public static ushort ToUShort(this byte[] bytes, int startIndex = 0)
10193
}
10294

10395

104-
/// <summary>
105-
/// 转换为字节数组
96+
/// <summary> 转换为字节数组
10697
/// </summary>
10798
/// <param name="value"></param>
10899
/// <returns>字节数组</returns>
@@ -111,8 +102,7 @@ public static byte[] GetBytes(this uint value)
111102
return BitConverter.GetBytes(value);
112103
}
113104

114-
/// <summary>
115-
/// 由字节数组中指定的位置转换
105+
/// <summary> 由字节数组中指定的位置转换
116106
/// </summary>
117107
/// <param name="bytes">字节数组</param>
118108
/// <param name="startIndex">开始的位置</param>
@@ -123,8 +113,7 @@ public static uint ToUInt(this byte[] bytes, int startIndex = 0)
123113
}
124114

125115

126-
/// <summary>
127-
/// 转换为字节数组
116+
/// <summary> 转换为字节数组
128117
/// </summary>
129118
/// <param name="value"></param>
130119
/// <returns>字节数组</returns>
@@ -133,8 +122,7 @@ public static byte[] GetBytes(this ulong value)
133122
return BitConverter.GetBytes(value);
134123
}
135124

136-
/// <summary>
137-
/// 由字节数组中指定的位置转换
125+
/// <summary> 由字节数组中指定的位置转换
138126
/// </summary>
139127
/// <param name="bytes">字节数组</param>
140128
/// <param name="startIndex">开始的位置</param>
@@ -145,8 +133,7 @@ public static ulong ToULong(this byte[] bytes, int startIndex = 0)
145133
}
146134

147135

148-
/// <summary>
149-
/// 转换为字节数组
136+
/// <summary> 转换为字节数组
150137
/// </summary>
151138
/// <param name="value"></param>
152139
/// <returns>字节数组</returns>
@@ -155,8 +142,7 @@ public static byte[] GetBytes(this float value)
155142
return BitConverter.GetBytes(value);
156143
}
157144

158-
/// <summary>
159-
/// 由字节数组中指定的位置转换
145+
/// <summary> 由字节数组中指定的位置转换
160146
/// </summary>
161147
/// <param name="bytes">字节数组</param>
162148
/// <param name="startIndex">开始的位置</param>
@@ -167,8 +153,7 @@ public static float ToFloat(this byte[] bytes, int startIndex = 0)
167153
}
168154

169155

170-
/// <summary>
171-
/// 转换为字节数组
156+
/// <summary> 转换为字节数组
172157
/// </summary>
173158
/// <param name="value"></param>
174159
/// <returns>字节数组</returns>
@@ -177,8 +162,7 @@ public static byte[] GetBytes(this double value)
177162
return BitConverter.GetBytes(value);
178163
}
179164

180-
/// <summary>
181-
/// 由字节数组中指定的位置转换
165+
/// <summary> 由字节数组中指定的位置转换
182166
/// </summary>
183167
/// <param name="bytes">字节数组</param>
184168
/// <param name="startIndex">开始的位置</param>
@@ -189,8 +173,7 @@ public static double ToDouble(this byte[] bytes, int startIndex = 0)
189173
}
190174

191175

192-
/// <summary>
193-
/// 转换为字节数组
176+
/// <summary> 转换为字节数组
194177
/// </summary>
195178
/// <param name="value"></param>
196179
/// <returns>字节数组</returns>
@@ -199,8 +182,7 @@ public static byte[] GetBytes(this char value)
199182
return BitConverter.GetBytes(value);
200183
}
201184

202-
/// <summary>
203-
/// 由字节数组中指定的位置转换
185+
/// <summary> 由字节数组中指定的位置转换
204186
/// </summary>
205187
/// <param name="bytes">字节数组</param>
206188
/// <param name="startIndex">开始的位置</param>
@@ -211,8 +193,7 @@ public static char ToChar(this byte[] bytes, int startIndex = 0)
211193
}
212194

213195

214-
/// <summary>
215-
/// 转换为字节数组
196+
/// <summary> 转换为字节数组
216197
/// </summary>
217198
/// <param name="value"></param>
218199
/// <returns>字节数组</returns>
@@ -221,8 +202,7 @@ public static byte[] GetBytes(this bool value)
221202
return BitConverter.GetBytes(value);
222203
}
223204

224-
/// <summary>
225-
/// 由字节数组中指定的位置转换
205+
/// <summary> 由字节数组中指定的位置转换
226206
/// </summary>
227207
/// <param name="bytes">字节数组</param>
228208
/// <param name="startIndex">开始的位置</param>
@@ -233,31 +213,56 @@ public static bool ToBool(this byte[] bytes, int startIndex = 0)
233213
}
234214

235215

236-
/// <summary>
237-
/// 转换为字节数组
216+
/// <summary> 转换为字节数组
238217
/// </summary>
239218
/// <param name="value"></param>
240-
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Default)</param>
219+
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Unicode)</param>
241220
/// <returns>字节数组</returns>
242221
public static byte[] GetBytes(this string value, System.Text.Encoding encoding = null)
243222
{
244223
if (encoding == null)
245-
encoding = System.Text.Encoding.Default;
224+
encoding = System.Text.Encoding.Unicode;
246225
return encoding.GetBytes(value);
247226
}
248227

249-
/// <summary>
250-
/// 由字节数组中指定的位置转换
228+
/// <summary> 由字节数组中指定的位置转换
251229
/// </summary>
252230
/// <param name="bytes">字节数组</param>
253-
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Default)</param>
231+
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Unicode)</param>
254232
/// <returns></returns>
255233
public static string ToString(this byte[] bytes, System.Text.Encoding encoding = null)
256234
{
257235
if (encoding == null)
258-
encoding = System.Text.Encoding.Default;
236+
encoding = System.Text.Encoding.Unicode;
259237
return encoding.GetString(bytes);
260238
}
239+
240+
/// <summary> 将 8 位无符号整数的数组转换为其用 Base64 数字编码的等效字符串表示形式
241+
/// </summary>
242+
/// <param name="bytes">一个 8 位无符号整数数组</param>
243+
/// <param name="option">如果每 76 个字符插入一个分行符,则使用 InsertLineBreaks,如果不插入分行符,则使用 None</param>
244+
/// <returns></returns>
245+
public static string ToBase64String(this byte[] bytes, Base64FormattingOptions option = Base64FormattingOptions.None)
246+
{
247+
if (bytes == null)
248+
return String.Empty;
249+
return Convert.ToBase64String(bytes, option);
250+
}
251+
252+
/// <summary> 将 8 位无符号整数的数组转换为其用 Base64 数字编码的等效字符串表示形式
253+
/// </summary>
254+
/// <param name="bytes">一个 8 位无符号整数数组</param>
255+
/// <param name="offset">bytes 数组中的偏移量</param>
256+
/// <param name="length">要转换的 bytes 的元素数</param>
257+
/// <param name="option">如果每 76 个字符插入一个分行符,则使用 InsertLineBreaks,如果不插入分行符,则使用 None</param>
258+
/// <returns></returns>
259+
public static string ToBase64String(this byte[] bytes, int offset, int length, Base64FormattingOptions option = Base64FormattingOptions.None)
260+
{
261+
if (bytes == null)
262+
return String.Empty;
263+
return Convert.ToBase64String(bytes, offset, length, option);
264+
}
265+
261266
}
262267
#endregion
263268

Src/Core/EConvertType.tt

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ namespace WSharp.Core
4545
string lower = to.ToLower();
4646
#>
4747

48-
/// <summary>
49-
/// 转换为字节数组
48+
/// <summary> 转换为字节数组
5049
/// </summary>
5150
/// <param name="value"></param>
5251
/// <returns>字节数组</returns>
@@ -55,8 +54,7 @@ namespace WSharp.Core
5554
return BitConverter.GetBytes(value);
5655
}
5756

58-
/// <summary>
59-
/// 由字节数组中指定的位置转换
57+
/// <summary> 由字节数组中指定的位置转换
6058
/// </summary>
6159
/// <param name="bytes">字节数组</param>
6260
/// <param name="startIndex">开始的位置</param>
@@ -68,31 +66,56 @@ namespace WSharp.Core
6866

6967
<# } #>
7068

71-
/// <summary>
72-
/// 转换为字节数组
69+
/// <summary> 转换为字节数组
7370
/// </summary>
7471
/// <param name="value"></param>
75-
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Default)</param>
72+
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Unicode)</param>
7673
/// <returns>字节数组</returns>
7774
public static byte[] GetBytes(this string value, System.Text.Encoding encoding = null)
7875
{
7976
if (encoding == null)
80-
encoding = System.Text.Encoding.Default;
77+
encoding = System.Text.Encoding.Unicode;
8178
return encoding.GetBytes(value);
8279
}
8380

84-
/// <summary>
85-
/// 由字节数组中指定的位置转换
81+
/// <summary> 由字节数组中指定的位置转换
8682
/// </summary>
8783
/// <param name="bytes">字节数组</param>
88-
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Default)</param>
84+
/// <param name="encoding">编码方式(如果为null,使用System.Text.Encoding.Unicode)</param>
8985
/// <returns></returns>
9086
public static string ToString(this byte[] bytes, System.Text.Encoding encoding = null)
9187
{
9288
if (encoding == null)
93-
encoding = System.Text.Encoding.Default;
89+
encoding = System.Text.Encoding.Unicode;
9490
return encoding.GetString(bytes);
9591
}
92+
93+
/// <summary> 将 8 位无符号整数的数组转换为其用 Base64 数字编码的等效字符串表示形式
94+
/// </summary>
95+
/// <param name="bytes">一个 8 位无符号整数数组</param>
96+
/// <param name="option">如果每 76 个字符插入一个分行符,则使用 InsertLineBreaks,如果不插入分行符,则使用 None</param>
97+
/// <returns></returns>
98+
public static string ToBase64String(this byte[] bytes, Base64FormattingOptions option = Base64FormattingOptions.None)
99+
{
100+
if (bytes == null)
101+
return String.Empty;
102+
return Convert.ToBase64String(bytes, option);
103+
}
104+
105+
/// <summary> 将 8 位无符号整数的数组转换为其用 Base64 数字编码的等效字符串表示形式
106+
/// </summary>
107+
/// <param name="bytes">一个 8 位无符号整数数组</param>
108+
/// <param name="offset">bytes 数组中的偏移量</param>
109+
/// <param name="length">要转换的 bytes 的元素数</param>
110+
/// <param name="option">如果每 76 个字符插入一个分行符,则使用 InsertLineBreaks,如果不插入分行符,则使用 None</param>
111+
/// <returns></returns>
112+
public static string ToBase64String(this byte[] bytes, int offset, int length, Base64FormattingOptions option = Base64FormattingOptions.None)
113+
{
114+
if (bytes == null)
115+
return String.Empty;
116+
return Convert.ToBase64String(bytes, offset, length, option);
117+
}
118+
96119
}
97120
#endregion
98121

0 commit comments

Comments
 (0)