Skip to content

Commit 24573b7

Browse files
authored
2026/03/31 Name fix
更名所有release方法为return,保留并废弃大部分release代码 框架更为.NET Standard2.0用于适配.NETCore/.NETFramework/.NET
1 parent a87b807 commit 24573b7

16 files changed

Lines changed: 196 additions & 71 deletions

PoolingLib/BasePool.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ public virtual TObject Get()
2929
return new();
3030
}
3131
/// <inheritdoc/>
32-
public virtual void Release(TObject obj)
32+
public virtual void Return(TObject obj)
3333
{
3434
_pool.Enqueue(obj);
3535
}
36+
/// <summary>
37+
/// 归还对象到对象池内
38+
/// </summary>
39+
/// <param name="obj">要归还的对象</param>
40+
[Obsolete("已更名为Return方法")]
41+
public virtual void Release(TObject obj)
42+
{
43+
Return(obj);
44+
}
3645
}
3746
/// <summary>
3847
/// 一个基础的池化类,可以继承该类创建其他对象池,该池化类内置了允许自定义的静态池
@@ -63,9 +72,18 @@ public virtual TObject Get()
6372
return new();
6473
}
6574
/// <inheritdoc/>
66-
public virtual void Release(TObject obj)
75+
public virtual void Return(TObject obj)
6776
{
6877
_pool.Enqueue(obj);
6978
}
79+
/// <summary>
80+
/// 归还对象到对象池内
81+
/// </summary>
82+
/// <param name="obj">要归还的对象</param>
83+
[Obsolete("已更名为Return方法")]
84+
public virtual void Release(TObject obj)
85+
{
86+
Return(obj);
87+
}
7088
}
7189
}

PoolingLib/Extensions/PoolExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public static class PoolExtensions
1414
/// <typeparam name="TObject">对象池的泛型</typeparam>
1515
/// <param name="obj">要归还的对象</param>
1616
/// <param name="pool">目标对象池</param>
17-
public static void ReleaseTo<TObject>(this TObject obj,IPool<TObject> pool) where TObject : new()
17+
public static void ReturnTo<TObject>(this TObject obj,IPool<TObject> pool) where TObject : new()
1818
{
19-
pool.Release(obj);
19+
pool.Return(obj);
2020
}
2121
/// <summary>
2222
/// 将<see cref="StringBuilder"/>归还至指定的对象池
@@ -25,13 +25,13 @@ public static class PoolExtensions
2525
/// <param name="toString">是否返回文本</param>
2626
/// <returns><see cref="StringBuilder"/>转化成的文本,如果<see href="toString"/>参数为<see langword="false"/>则返回空字符串</returns>
2727
/// <exception cref="ArgumentNullException"></exception>
28-
public static string ReleaseTo(this StringBuilder sb, bool toString = false)
28+
public static string ReturnTo(this StringBuilder sb, bool toString = false)
2929
{
3030
if (toString)
31-
return StringBuilderPool.Pool.ToStringRelease(sb);
31+
return StringBuilderPool.Pool.ToStringReturn(sb);
3232
else
3333
{
34-
StringBuilderPool.Pool.Release(sb);
34+
StringBuilderPool.Pool.Return(sb);
3535
return string.Empty;
3636
}
3737
}

PoolingLib/IPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public interface IPool<TObject>
1515
/// 归还对象到对象池内
1616
/// </summary>
1717
/// <param name="obj">要归还的对象</param>
18-
public void Release(TObject obj);
18+
public void Return(TObject obj);
1919
}
2020
}

PoolingLib/PoolingLib.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net4.8</TargetFramework>
4+
<TargetFramework>netstandard2.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<LangVersion>latest</LangVersion>
88
<PlatformTarget>x64</PlatformTarget>
99
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
10+
<OutputType>Library</OutputType>
1011
<Authors>CnCSharp-DevTeam</Authors>
1112
<Description>A simple pooling library for dotnet
1213
一个面向.NET简易的池化库</Description>
1314
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1415
<Title>PoolingLib</Title>
1516
<RepositoryUrl>https://github.com/CnCSharp-Dev/PoolingLib</RepositoryUrl>
1617
<RepositoryType>git</RepositoryType>
17-
<AssemblyVersion>1.0.0.2</AssemblyVersion>
18+
<AssemblyVersion>1.0.0.3</AssemblyVersion>
1819
<PackageProjectUrl>github.com/CnCSharp-Dev/PoolingLib</PackageProjectUrl>
1920
<PackageReadmeFile>README.md</PackageReadmeFile>
2021
<PackageIcon>icon.png</PackageIcon>
2122
<PackageLicenseFile>LICENSE</PackageLicenseFile>
22-
<FileVersion>1.0.0.2</FileVersion>
23-
<Version>1.0.2</Version>
23+
<FileVersion>1.0.0.3</FileVersion>
24+
<Version>1.0.3</Version>
2425
<GenerateDocumentationFile>True</GenerateDocumentationFile>
2526
</PropertyGroup>
2627

@@ -29,7 +30,7 @@
2930
<DebugType>portable</DebugType>
3031
</PropertyGroup>
3132

32-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
33+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Return|AnyCPU'">
3334
<DebugType>portable</DebugType>
3435
</PropertyGroup>
3536

PoolingLib/Pools/CollectionPool.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Collection<TObject> Get(IList<TObject> list)
2626

2727
/// <inheritdoc/>
2828
/// <exception cref="ArgumentNullException"></exception>
29-
public override void Release(Collection<TObject> collection)
29+
public override void Return(Collection<TObject> collection)
3030
{
3131
if (collection == null)
3232
throw new ArgumentNullException(nameof(collection));
@@ -40,14 +40,25 @@ public override void Release(Collection<TObject> collection)
4040
/// <param name="collection">要返还的栈</param>
4141
/// <returns>对象数组</returns>
4242
/// <exception cref="ArgumentNullException"></exception>
43-
public TObject[] ToArrayRelease(Collection<TObject> collection)
43+
public TObject[] ToArrayReturn(Collection<TObject> collection)
4444
{
4545
if (collection == null)
4646
throw new ArgumentNullException(nameof(collection));
4747

4848
TObject[] array = [.. collection];
49-
Release(collection);
49+
Return(collection);
5050
return array;
5151
}
52+
/// <summary>
53+
/// 将<see cref="Collection{TObject}"/>转化为数组,同时返回至对象池
54+
/// </summary>
55+
/// <param name="collection">要返还的栈</param>
56+
/// <returns>对象数组</returns>
57+
/// <exception cref="ArgumentNullException"></exception>
58+
[Obsolete("已更名为ToArrayReturn方法")]
59+
public TObject[] ToArrayRelease(Collection<TObject> collection)
60+
{
61+
return ToArrayReturn(collection);
62+
}
5263
}
5364
}

PoolingLib/Pools/ConcurrentBagPool.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ConcurrentBag<TObject> Get(IEnumerable<TObject> collection)
3737
/// </summary>
3838
/// <param name="bag">要归还的对象</param>
3939
/// <exception cref="ArgumentNullException"></exception>
40-
public override void Release(ConcurrentBag<TObject> bag)
40+
public override void Return(ConcurrentBag<TObject> bag)
4141
{
4242
if (bag == null)
4343
throw new ArgumentNullException(nameof(bag));
@@ -51,14 +51,24 @@ public override void Release(ConcurrentBag<TObject> bag)
5151
/// </summary>
5252
/// <param name="bag">要返还的包</param>
5353
/// <returns>包含包中所有元素的数组</returns>
54-
public TObject[] ToArrayRelease(ConcurrentBag<TObject> bag)
54+
public TObject[] ToArrayReturn(ConcurrentBag<TObject> bag)
5555
{
5656
if (bag == null)
5757
throw new ArgumentNullException(nameof(bag));
5858

5959
TObject[] array = [.. bag];
60-
Release(bag);
60+
Return(bag);
6161
return array;
62+
}
63+
/// <summary>
64+
/// 将 <see cref="ConcurrentBag{TObject}"/> 转化为数组,同时返回至对象池
65+
/// </summary>
66+
/// <param name="bag">要返还的包</param>
67+
/// <returns>包含包中所有元素的数组</returns>
68+
[Obsolete("已更名为ToArrayReturn方法")]
69+
public TObject[] ToArrayRelease(ConcurrentBag<TObject> bag)
70+
{
71+
return ToArrayReturn(bag);
6272
}
6373
}
6474
}

PoolingLib/Pools/Dictionaries/DictionaryPool.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Dictionary<TKey, TValue> Get(int capacity)
2424
}
2525
/// <inheritdoc/>
2626
/// <exception cref="ArgumentNullException"></exception>
27-
public override void Release(Dictionary<TKey, TValue> dict)
27+
public override void Return(Dictionary<TKey, TValue> dict)
2828
{
2929
if (dict == null)
3030
throw new ArgumentNullException(nameof(dict));
@@ -38,14 +38,25 @@ public override void Release(Dictionary<TKey, TValue> dict)
3838
/// <param name="obj">要返还的字典</param>
3939
/// <returns>对象数组</returns>
4040
/// <exception cref="ArgumentNullException"></exception>
41-
public KeyValuePair<TKey, TValue>[] ToArrayRelease(Dictionary<TKey, TValue> obj)
41+
public KeyValuePair<TKey, TValue>[] ToArrayReturn(Dictionary<TKey, TValue> obj)
4242
{
4343
if (obj == null)
4444
throw new ArgumentNullException(nameof(obj));
4545

4646
KeyValuePair<TKey, TValue>[] array = [.. obj];
47-
Release(obj);
47+
Return(obj);
4848
return array;
4949
}
50+
/// <summary>
51+
/// 将 <see cref="Dictionary{TKey, TValue}"/> 转换为键值对数组,同时返回至对象池
52+
/// </summary>
53+
/// <param name="dict">要返还的字典</param>
54+
/// <returns>键值对数组</returns>
55+
/// <exception cref="ArgumentNullException"></exception>
56+
[Obsolete("已更名为ToArrayReturn方法")]
57+
public KeyValuePair<TKey, TValue>[] ToArrayRelease(Dictionary<TKey, TValue> dict)
58+
{
59+
return ToArrayReturn(dict);
60+
}
5061
}
5162
}

PoolingLib/Pools/Dictionaries/SortedDictionaryPool.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public override SortedDictionary<TKey, TValue> Get()
1616
}
1717
/// <inheritdoc/>
1818
/// <exception cref="ArgumentNullException"></exception>
19-
public override void Release(SortedDictionary<TKey, TValue> dict)
19+
public override void Return(SortedDictionary<TKey, TValue> dict)
2020
{
2121
if (dict == null)
2222
throw new ArgumentNullException(nameof(dict));
@@ -30,15 +30,26 @@ public override void Release(SortedDictionary<TKey, TValue> dict)
3030
/// <param name="dict">要返还的字典</param>
3131
/// <returns>键值对数组</returns>
3232
/// <exception cref="ArgumentNullException"></exception>
33-
public KeyValuePair<TKey, TValue>[] ToArrayRelease(SortedDictionary<TKey, TValue> dict)
33+
public KeyValuePair<TKey, TValue>[] ToArrayReturn(SortedDictionary<TKey, TValue> dict)
3434
{
3535
if (dict == null)
3636
throw new ArgumentNullException(nameof(dict));
3737

3838
KeyValuePair<TKey, TValue>[] array = new KeyValuePair<TKey, TValue>[dict.Count];
3939
((ICollection<KeyValuePair<TKey, TValue>>)dict).CopyTo(array, 0);
40-
Release(dict);
40+
Return(dict);
4141
return array;
4242
}
43+
/// <summary>
44+
/// 将 <see cref="SortedDictionary{TKey, TValue}"/> 转换为键值对数组,同时返回至对象池
45+
/// </summary>
46+
/// <param name="dict">要返还的字典</param>
47+
/// <returns>键值对数组</returns>
48+
/// <exception cref="ArgumentNullException"></exception>
49+
[Obsolete("已更名为ToArrayReturn方法")]
50+
public KeyValuePair<TKey, TValue>[] ToArrayRelease(SortedDictionary<TKey, TValue> dict)
51+
{
52+
return ToArrayReturn(dict);
53+
}
4354
}
4455
}

PoolingLib/Pools/LinkedListPool.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace PoolingLib.Pools
1+
using System.Collections.Concurrent;
2+
3+
namespace PoolingLib.Pools
24
{
35
/// <summary>
46
/// <see cref="LinkedList{TObject}"/>对象池
@@ -32,7 +34,7 @@ public LinkedList<TObject> Get(IEnumerable<TObject> collection)
3234
}
3335
/// <inheritdoc/>
3436
/// <exception cref="ArgumentNullException"></exception>
35-
public override void Release(LinkedList<TObject> list)
37+
public override void Return(LinkedList<TObject> list)
3638
{
3739
if (list == null)
3840
throw new ArgumentNullException(nameof(list));
@@ -46,14 +48,25 @@ public override void Release(LinkedList<TObject> list)
4648
/// <param name="list">要返还的哈希列表</param>
4749
/// <returns>对象数组</returns>
4850
/// <exception cref="ArgumentNullException"></exception>
49-
public TObject[] ToArrayRelease(LinkedList<TObject> list)
51+
public TObject[] ToArrayReturn(LinkedList<TObject> list)
5052
{
5153
if (list == null)
5254
throw new ArgumentNullException(nameof(list));
5355

5456
TObject[] array = [.. list];
55-
Release(list);
57+
Return(list);
5658
return array;
5759
}
60+
/// <summary>
61+
/// 将<see cref="LinkedList{TObject}"/>转化为数组,同时返回至对象池
62+
/// </summary>
63+
/// <param name="list">要返还的哈希列表</param>
64+
/// <returns>对象数组</returns>
65+
/// <exception cref="ArgumentNullException"></exception>
66+
[Obsolete("已更名为ToArrayReturn方法")]
67+
public TObject[] ToArrayRelease(LinkedList<TObject> list)
68+
{
69+
return ToArrayReturn(list);
70+
}
5871
}
5972
}

PoolingLib/Pools/ListPool.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public List<TObject> Get(int capacity)
4040
}
4141
/// <inheritdoc/>
4242
/// <exception cref="ArgumentNullException"></exception>
43-
public override void Release(List<TObject> list)
43+
public override void Return(List<TObject> list)
4444
{
4545
if (list == null)
4646
throw new ArgumentNullException(nameof(list));
@@ -54,14 +54,25 @@ public override void Release(List<TObject> list)
5454
/// <param name="list">要返还的列表</param>
5555
/// <returns>对象数组</returns>
5656
/// <exception cref="ArgumentNullException"></exception>
57-
public TObject[] ToArrayRelease(List<TObject> list)
57+
public TObject[] ToArrayReturn(List<TObject> list)
5858
{
5959
if (list == null)
6060
throw new ArgumentNullException(nameof(list));
6161

6262
TObject[] array = [.. list];
63-
Release(list);
63+
Return(list);
6464
return array;
6565
}
66+
/// <summary>
67+
/// 将<see cref="List{TObject}"/>转化为数组,同时返回至对象池
68+
/// </summary>
69+
/// <param name="list">要返还的列表</param>
70+
/// <returns>对象数组</returns>
71+
/// <exception cref="ArgumentNullException"></exception>
72+
[Obsolete("已更名为ToArrayReturn方法")]
73+
public TObject[] ToArrayRelease(List<TObject> list)
74+
{
75+
return ToArrayReturn(list);
76+
}
6677
}
6778
}

0 commit comments

Comments
 (0)