Skip to content

Commit c1add88

Browse files
committed
Update README.md
1 parent b7f5170 commit c1add88

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

README.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
此函式庫包含多個擴充方法,分為以下類別,適用於多種場景的 C# 開發需求:
88

9-
### **1. BinaryExtensions**
9+
### 1. `BinaryExtensions`
1010
提供針對二進位資料的操作方法:
1111
- 寫入分段二進位資料:`Write`
1212
- 資料加密與解密(AES):`ToAES``FromAES`
1313
- 資料格式轉換(Base64、Hex、MD5、UTF8):`ToBase64``ToHex``ToMD5``ToUTF8`
1414

15-
### **2. CollectionExtensions**
15+
### 2. `CollectionExtensions`
1616
提供集合類型的操作方法:
1717
- 判斷集合是否為空:`IsNullOrEmpty`
1818
- 增加或更新字典的元素:`AddRange``Update``UpdateRange`
@@ -21,34 +21,34 @@
2121
- 對字典進行累加或條件移除:`Sum``RemoveWhere`
2222
- 針對 `HashSet``List` 提供字串分割並新增元素的功能:`AddRange`
2323

24-
### **3. DelegateExtensions**
24+
### 3. `DelegateExtensions`
2525
提供委託(Delegate)操作的擴充方法:
2626
- 合併或移除委託:`Combine``Remove`
2727
- 註冊或取消註冊委託:`Register`
2828
- 安全執行委託並獲取結果:`TryInvoke``GetResults`
2929

30-
### **4. MathExtensions**
30+
### 4. `MathExtensions`
3131
提供數值運算的輔助方法:
3232
- 數值的取整與截斷:`Round``Truncate`
3333
- 數值範圍限制與距離計算:`Clamp``Distance`
3434
- 數值轉換(整數、浮點數、布林值、列舉):`ToInt``ToFloat``ToBoolean``ToEnum`
3535
- 判斷數值是否為指定列舉類型:`IsDefined`
3636

37-
### **5. ReflectionExtensions**
37+
### 5. `ReflectionExtensions`
3838
提供基於反射的屬性與欄位操作方法:
3939
- 取得屬性或欄位值:`GetFieldValue``GetPropertyValue`
4040
- 設定屬性或欄位值:`SetFieldValue``SetPropertyValue`
4141
- 取得類型的指定屬性:`GetAttribute`
4242

43-
### **6. StringExtensions**
43+
### 6. `StringExtensions`
4444
提供針對字串的操作與轉換方法:
4545
- 字串比較與串接:`Compare``Concat`
4646
- 格式化與字串分割:`Format``TrySplit`
4747
- 字串轉換(Base64、數值、列舉):`ToBase64``ToInt``ToEnum`
4848
- 字串修訂(大小寫、移除子字串):`ToLower``ToUpper``Remove`
4949
- 判斷字串是否符合條件(空白、字母數字):`IsNullOrEmpty``IsLetterOrDigit`
5050

51-
### **7. TimeExtensions**
51+
### 7. `TimeExtensions`
5252
提供時間與日期的輔助操作方法:
5353
- 計算剩餘時間(分鐘或秒):`GetRemainingMinutes``GetRemainingSeconds`
5454
- 計算時間差(分鐘或秒):`GetDifferenceInMinutes``GetDifferenceInSeconds`
@@ -63,7 +63,7 @@
6363

6464
### Binary Extensions
6565

66-
1. **Write**
66+
1. `Write`
6767
```csharp
6868
public static void Write(this BinaryWriter writer, byte[] data, int buffer)
6969
```
@@ -80,7 +80,7 @@ using (var writer = new BinaryWriter(stream))
8080
}
8181
```
8282

83-
2. **ToAES**
83+
2. `ToAES`
8484
```csharp
8585
public static byte[] ToAES(this byte[] data, string key, string iv)
8686
```
@@ -92,9 +92,11 @@ string iv = "my-initialization-vector";
9292
byte[] encryptedData = originalData.ToAES(key, iv); // 將資料加密
9393
```
9494

95+
---
96+
9597
### Collection Extensions
9698

97-
1. **IsNullOrEmpty**
99+
1. `IsNullOrEmpty`
98100
```csharp
99101
public static bool IsNullOrEmpty<TSource>(this ICollection<TSource> collection)
100102
```
@@ -103,7 +105,7 @@ var collection = new List<int>();
103105
bool isEmpty = collection.IsNullOrEmpty(); // 判斷集合是否為 null 或空
104106
```
105107

106-
2. **TryAdd**
108+
2. `TryAdd`
107109
```csharp
108110
public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
109111
```
@@ -112,7 +114,7 @@ var dictionary = new Dictionary<string, int>();
112114
bool added = dictionary.TryAdd("key1", 100); // 嘗試新增鍵值,若已存在則回傳 false
113115
```
114116

115-
3. **ForEach**
117+
3. `ForEach`
116118
```csharp
117119
public static void ForEach<TSource>(this IEnumerable<TSource> collection, Action<TSource> action)
118120
```
@@ -123,9 +125,11 @@ var results = new List<int>();
123125
numbers.ForEach(num => results.Add(num * 2)); // 將每個數字乘以 2 並加入 results
124126
```
125127

128+
---
129+
126130
### Delegate Extensions
127131

128-
1. **Register**
132+
1. `Register`
129133
```csharp
130134
public static TSource Register<TSource>(this TSource source, TSource toRegister, bool isEnable) where TSource : Delegate
131135
```
@@ -137,7 +141,7 @@ action = action.Register(additionalAction, true); // 將 additionalAction 註冊
137141
action(5); // 執行所有註冊的行為
138142
```
139143

140-
2. **GetResults**
144+
2. `GetResults`
141145
```csharp
142146
public static void GetResults<TResult>(this Func<TResult> func, List<TResult> results)
143147
```
@@ -148,9 +152,11 @@ var results = new List<int>();
148152
func.GetResults(results); // 將每次執行的結果加入 results 清單
149153
```
150154

155+
---
156+
151157
### Math Extensions
152158

153-
1. **Clamp**
159+
1. `Clamp`
154160
```csharp
155161
public static float Clamp(this float value, float min, float max)
156162
```
@@ -159,7 +165,7 @@ float value = 120f;
159165
float clampedValue = value.Clamp(0f, 100f); // 將數值限制在 0 到 100 之間
160166
```
161167

162-
2. **Distance**
168+
2. `Distance`
163169
```csharp
164170
public static float Distance(this float source, float destination)
165171
```
@@ -169,9 +175,11 @@ float point2 = 25.3f;
169175
float distance = point1.Distance(point2); // 計算兩點之間的距離
170176
```
171177

178+
---
179+
172180
### Reflection Extensions
173181

174-
1. **GetFieldValue**
182+
1. `GetFieldValue`
175183
```csharp
176184
public static object GetFieldValue(this object obj, string name)
177185
```
@@ -185,7 +193,7 @@ var sample = new Sample();
185193
object fieldValue = sample.GetFieldValue("_hiddenField"); // 取得私有欄位的值
186194
```
187195

188-
2. **SetPropertyValue**
196+
2. `SetPropertyValue`
189197
```csharp
190198
public static void SetPropertyValue(this object obj, string name, object value)
191199
```
@@ -199,9 +207,11 @@ var sample = new Sample();
199207
sample.SetPropertyValue("Name", "New Value"); // 設定屬性值為 "New Value"
200208
```
201209

210+
---
211+
202212
### String Extensions
203213

204-
1. **GetName**
214+
1. `GetName`
205215
```csharp
206216
public static string GetName<TEnum>(this TEnum source) where TEnum : Enum
207217
```
@@ -212,7 +222,7 @@ Colors color = Colors.Green;
212222
string name = color.GetName(); // 取得列舉值的名稱 "Green"
213223
```
214224

215-
2. **ToEnum**
225+
2. `ToEnum`
216226
```csharp
217227
public static TEnum ToEnum<TEnum>(this string str) where TEnum : struct, Enum
218228
```
@@ -221,7 +231,7 @@ string colorName = "Blue";
221231
Colors color = colorName.ToEnum<Colors>(); // 將字串轉換為列舉值 Colors.Blue
222232
```
223233

224-
3. **ToLower**
234+
3. `ToLower`
225235
```csharp
226236
public static string ToLower(this string source, int index)
227237
```
@@ -230,7 +240,7 @@ string input = "HELLO";
230240
string result = input.ToLower(0); // 將索引 0 的字母轉為小寫,結果為 "hELLO"
231241
```
232242

233-
4. **Remove**
243+
4. `Remove`
234244
```csharp
235245
public static void Remove(this StringBuilder source, string str)
236246
```
@@ -239,9 +249,11 @@ var builder = new StringBuilder("Hello, World!");
239249
builder.Remove("World"); // 移除 "World" 子字串,結果為 "Hello, !"
240250
```
241251

252+
---
253+
242254
### Time Extensions
243255

244-
1. **GetRemainingSeconds**
256+
1. `GetRemainingSeconds`
245257
```csharp
246258
public static double GetRemainingSeconds(this DateTime date)
247259
```
@@ -250,7 +262,7 @@ DateTime now = DateTime.Now;
250262
double remainingSeconds = now.GetRemainingSeconds(); // 計算當天剩餘秒數
251263
```
252264

253-
2. **GetDifferenceInSeconds**
265+
2. `GetDifferenceInSeconds`
254266
```csharp
255267
public static double GetDifferenceInSeconds(this TimeSpan span, TimeSpan value)
256268
```

0 commit comments

Comments
 (0)