返回提交历史
Modified
XFEExtension.NetCore.AutoConfig/ProfileInfo.cs
+2
-2
Added
XFEExtension.NetCore.AutoConfig/ProfileList.cs
+162
-0
Modified
XFEExtension.NetCore.AutoConfig/XFEExtension.NetCore.AutoConfig.csproj
+4
-3
XFEstudio/XFEExtension.NetCore.AutoConfig
change-调整了配置文件的默认储存位置 => 从/Profiles/xxx.xfe调整为/Profiles/xxx.xpf文件 add-新增ProfileList,该类型与List功能类似,但是其可以在调用Add、Remove、Clear等对列表进行增删改的操作时自动保存
9a8277d
代码差异
3 个文件
+168
-5
@@ -46,9 +46,9 @@ public class ProfileInfo
46
46
else
47
47
{
48
48
if (XFEProfile.ProfilesDefaultPath[^1] == '/' || XFEProfile.ProfilesDefaultPath[^1] == '\\')
49
Path = $"{XFEProfile.ProfilesDefaultPath}{profileType.Name}.xfe";
49
Path = $"{XFEProfile.ProfilesDefaultPath}{profileType.Name}.xpf";
50
50
else
51
Path = $"{XFEProfile.ProfilesDefaultPath}/{profileType.Name}.xfe";
51
Path = $"{XFEProfile.ProfilesDefaultPath}/{profileType.Name}.xpf";
52
52
}
53
53
}
54
54
else
@@ -0,0 +1,162 @@
1
using System.Collections;
2
3
namespace XFEExtension.NetCore.AutoConfig;
4
5
/// <summary>
6
/// 配置文件列表
7
/// </summary>
8
/// <typeparam name="T">列表泛型</typeparam>
9
/// <typeparam name="P">配置文件泛型</typeparam>
10
public class ProfileList<T, P> : ICollection<T>, IEnumerable<T>, IEnumerable, IList<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection, IList
11
{
12
private readonly List<T> innerList;
13
14
/// <summary>
15
/// 空列表
16
/// </summary>
17
public ProfileList() => innerList = [];
18
19
/// <summary>
20
/// 使用已有列表创建
21
/// </summary>
22
/// <param name="innerList">已有列表</param>
23
public ProfileList(List<T> innerList) => this.innerList = innerList;
24
25
///<inheritdoc/>
26
public T this[int index] { get => ((IList<T>)innerList)[index]; set => ((IList<T>)innerList)[index] = value; }
27
object? IList.this[int index] { get => ((IList)innerList)[index]; set => ((IList)innerList)[index] = value; }
28
29
///<inheritdoc/>
30
public int Count => ((ICollection<T>)innerList).Count;
31
32
///<inheritdoc/>
33
public bool IsReadOnly => ((ICollection<T>)innerList).IsReadOnly;
34
35
///<inheritdoc/>
36
public bool IsSynchronized => ((ICollection)innerList).IsSynchronized;
37
38
///<inheritdoc/>
39
public object SyncRoot => ((ICollection)innerList).SyncRoot;
40
41
///<inheritdoc/>
42
public bool IsFixedSize => ((IList)innerList).IsFixedSize;
43
44
///<inheritdoc/>
45
public void Add(T item)
46
{
47
((ICollection<T>)innerList).Add(item);
48
XFEProfile.SaveProfile(typeof(P));
49
}
50
51
///<inheritdoc/>
52
public int Add(object? value)
53
{
54
var result = ((IList)innerList).Add(value);
55
XFEProfile.SaveProfile(typeof(P));
56
return result;
57
}
58
59
///<inheritdoc/>
60
public void AddRange(IEnumerable<T> collection)
61
{
62
innerList.AddRange(collection);
63
XFEProfile.SaveProfile(typeof(P));
64
}
65
66
///<inheritdoc/>
67
public void AddRange(ReadOnlySpan<T> source)
68
{
69
innerList.AddRange(source);
70
XFEProfile.SaveProfile(typeof(P));
71
}
72
73
///<inheritdoc/>
74
public void Clear()
75
{
76
((ICollection<T>)innerList).Clear();
77
XFEProfile.SaveProfile(typeof(P));
78
}
79
80
///<inheritdoc/>
81
public bool Contains(T item)
82
{
83
return ((ICollection<T>)innerList).Contains(item);
84
}
85
86
///<inheritdoc/>
87
public bool Contains(object? value)
88
{
89
return ((IList)innerList).Contains(value);
90
}
91
92
///<inheritdoc/>
93
public void CopyTo(T[] array, int arrayIndex)
94
{
95
((ICollection<T>)innerList).CopyTo(array, arrayIndex);
96
}
97
98
///<inheritdoc/>
99
public void CopyTo(Array array, int index)
100
{
101
((ICollection)innerList).CopyTo(array, index);
102
}
103
104
///<inheritdoc/>
105
public IEnumerator<T> GetEnumerator()
106
{
107
return ((IEnumerable<T>)innerList).GetEnumerator();
108
}
109
110
///<inheritdoc/>
111
public int IndexOf(T item)
112
{
113
return ((IList<T>)innerList).IndexOf(item);
114
}
115
116
///<inheritdoc/>
117
public int IndexOf(object? value)
118
{
119
return ((IList)innerList).IndexOf(value);
120
}
121
122
///<inheritdoc/>
123
public void Insert(int index, T item)
124
{
125
((IList<T>)innerList).Insert(index, item);
126
XFEProfile.SaveProfile(typeof(P));
127
}
128
129
///<inheritdoc/>
130
public void Insert(int index, object? value)
131
{
132
((IList)innerList).Insert(index, value);
133
XFEProfile.SaveProfile(typeof(P));
134
}
135
136
///<inheritdoc/>
137
public bool Remove(T item)
138
{
139
var result = ((ICollection<T>)innerList).Remove(item);
140
XFEProfile.SaveProfile(typeof(P));
141
return result;
142
}
143
144
///<inheritdoc/>
145
public void Remove(object? value)
146
{
147
((IList)innerList).Remove(value);
148
XFEProfile.SaveProfile(typeof(P));
149
}
150
151
///<inheritdoc/>
152
public void RemoveAt(int index)
153
{
154
((IList<T>)innerList).RemoveAt(index);
155
XFEProfile.SaveProfile(typeof(P));
156
}
157
158
IEnumerator IEnumerable.GetEnumerator()
159
{
160
return ((IEnumerable)innerList).GetEnumerator();
161
}
162
}
@@ -17,17 +17,18 @@
17
17
<PackageTags>XFE;config;profile;auto</PackageTags>
18
18
<PackageReleaseNotes>## 调整
19
19
20
无
20
调整了配置文件的默认储存位置 => 从/Profiles/xxx.xfe调整为/Profiles/xxx.xpf文件
21
21
22
22
## 新增
23
23
24
为每个配置文件类增加静态ProfilePath属性,可以使用引用路径,优先级大于ProfilePath特性
24
新增ProfileList,该类型与List功能类似,但是其可以在调用Add、Remove、Clear等对列表进行增删改的操作时自动保存
25
25
26
26
## 严重
27
27
28
28
无</PackageReleaseNotes>
29
29
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
30
<Version>1.1.1</Version>
30
<Version>1.2.0</Version>
31
<GenerateDocumentationFile>True</GenerateDocumentationFile>
31
32
</PropertyGroup>
32
33
33
34
<ItemGroup>