XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension

完善部分逻辑

9ff6606
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

12 个文件 +472 -648
Modified XFEExtension.NetCore/CyberComm/XCCNetWork/XCCMessageReceiveHelper.cs +2 -3
@@ -253,12 +253,11 @@ public class XCCMessageReceiveHelper
253 253 }
254 254 if (xCCFileDictionary.TryGetValue(e.MessageId!, out var value))
255 255 {
256 var xCCFile = value;
257 if (!xCCFile.Loaded)
256 if (!value.Loaded)
258 257 {
259 258 value.LoadFile(e.BinaryMessage);
260 259 if (AutoSaveInLocal)
261 SaveFile(xCCFile);
260 SaveFile(value);
262 261 }
263 262 }
264 263 else
Modified XFEExtension.NetCore/XFETransform/JsonConverter/JsonNodeConverter.cs +16 -28
@@ -10,15 +10,12 @@ public class JsonNodeConverter(string jsonString)
10 10 private string currentPropertyName = "";
11 11 private string currentPropertyValue = "";
12 12 private readonly List<short> currentPosition = new List<short> { 0 };
13 private string jsonString = jsonString;
13
14 14 /// <summary>
15 15 /// 原始Json字符串
16 16 /// </summary>
17 public string JsonString
18 {
19 get { return jsonString; }
20 set { jsonString = value; }
21 }
17 public string JsonString { get; set; } = jsonString;
18
22 19 /// <summary>
23 20 /// 转化为Json节点
24 21 /// </summary>
@@ -29,15 +26,14 @@ public class JsonNodeConverter(string jsonString)
29 26 var currentState = CurrentState.None;
30 27 var lastSymbol = JsonSymbol.Brace;
31 28 var currentSymbol = JsonSymbol.Brace;
32 for (var i = 0; i < jsonString.Length; i++)
29 foreach (var current in JsonString)
33 30 {
34 var current = jsonString[i];
35 31 var currentJsonComplexJsonNode = GetJsonNodeByIndex(jsonNode, currentPosition);
36 32 ValueType currentValueType;
37 33 switch (current)
38 34 {
39 35 case '{':
40 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue) || currentState == CurrentState.AfterPropertyValue || currentState == CurrentState.AfterProperty)
36 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue))
41 37 {
42 38 currentSymbol = JsonSymbol.Brace;
43 39 currentState = CurrentState.BeforeProperty;
@@ -65,7 +61,7 @@ public class JsonNodeConverter(string jsonString)
65 61 }
66 62 break;
67 63 case '}':
68 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue) || currentState == CurrentState.AfterPropertyValue || currentState == CurrentState.AfterProperty)
64 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue))
69 65 {
70 66 currentSymbol = JsonSymbol.InvertedBrace;
71 67 currentState = CurrentState.None;
@@ -73,7 +69,7 @@ public class JsonNodeConverter(string jsonString)
73 69 {
74 70 currentValueType = JudgeValueType(ref currentPropertyValue);
75 71 currentJsonComplexJsonNode = GetJsonNodeByIndex(jsonNode, currentPosition);
76 if (SummonJsonPropertyNode(currentValueType, currentLayer, currentPropertyName.Replace("\"", ""), currentPropertyValue) is JsonPropertyNode jsonPropertyNode)
72 if (SummonJsonPropertyNode(currentValueType, currentLayer, currentPropertyName.Replace("\"", ""), currentPropertyValue) is { } jsonPropertyNode)
77 73 currentJsonComplexJsonNode.DescendingNodes.Add(jsonPropertyNode);
78 74 else
79 75 Console.WriteLine($"设置复杂Json节点失败:{currentLayer}\t{currentPropertyName}\t{currentPropertyValue}");
@@ -94,7 +90,7 @@ public class JsonNodeConverter(string jsonString)
94 90 }
95 91 break;
96 92 case '[':
97 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue) || currentState == CurrentState.AfterPropertyValue || currentState == CurrentState.AfterProperty)
93 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue))
98 94 {
99 95 currentLayer++;
100 96 currentSymbol = JsonSymbol.Bracket;
@@ -121,14 +117,14 @@ public class JsonNodeConverter(string jsonString)
121 117 break;
122 118 case ']':
123 119 currentSymbol = JsonSymbol.InvertedBracket;
124 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue) || currentState == CurrentState.AfterPropertyValue || currentState == CurrentState.AfterProperty)
120 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue))
125 121 {
126 122 currentState = CurrentState.None;
127 123 if (lastSymbol is JsonSymbol.Text or JsonSymbol.DoubleQuotationMark)
128 124 {
129 125 currentValueType = JudgeValueType(ref currentPropertyValue);
130 126 currentJsonComplexJsonNode = GetJsonNodeByIndex(jsonNode, currentPosition);
131 if (SummonJsonPropertyNode(currentValueType, currentLayer, currentPropertyName.Replace("\"", ""), currentPropertyValue) is JsonPropertyNode jsonPropertyNode)
127 if (SummonJsonPropertyNode(currentValueType, currentLayer, currentPropertyName.Replace("\"", ""), currentPropertyValue) is { } jsonPropertyNode)
132 128 currentJsonComplexJsonNode.DescendingNodes.Add(jsonPropertyNode);
133 129 else
134 130 Console.WriteLine($"设置复杂Json节点失败:{currentLayer}\t{currentPropertyName}\t{currentPropertyValue}");
@@ -147,7 +143,7 @@ public class JsonNodeConverter(string jsonString)
147 143 }
148 144 break;
149 145 case ':':
150 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue) || currentState == CurrentState.AfterPropertyValue || currentState == CurrentState.AfterProperty)
146 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue))
151 147 {
152 148 currentSymbol = JsonSymbol.Colon;
153 149 currentState = CurrentState.BeforePropertyValue;
@@ -158,7 +154,7 @@ public class JsonNodeConverter(string jsonString)
158 154 }
159 155 break;
160 156 case ',':
161 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue) || currentState == CurrentState.AfterPropertyValue || currentState == CurrentState.AfterProperty)
157 if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue))
162 158 {
163 159 currentSymbol = JsonSymbol.Comma;
164 160 if (currentLayer >= -1)
@@ -169,7 +165,7 @@ public class JsonNodeConverter(string jsonString)
169 165 {
170 166 currentValueType = JudgeValueType(ref currentPropertyValue);
171 167 currentJsonComplexJsonNode = GetJsonNodeByIndex(jsonNode, currentPosition);
172 if (SummonJsonPropertyNode(currentValueType, currentLayer, currentPropertyName.Replace("\"", ""), currentPropertyValue) is JsonPropertyNode jsonPropertyNode)
168 if (SummonJsonPropertyNode(currentValueType, currentLayer, currentPropertyName.Replace("\"", ""), currentPropertyValue) is { } jsonPropertyNode)
173 169 currentJsonComplexJsonNode.DescendingNodes.Add(jsonPropertyNode);
174 170 else
175 171 Console.WriteLine($"设置复杂Json节点失败:{currentLayer}\t{currentPropertyName}\t{currentPropertyValue}");
@@ -217,9 +213,6 @@ public class JsonNodeConverter(string jsonString)
217 213 currentSymbol = JsonSymbol.Text;
218 214 break;
219 215 case CurrentState.PropertyValue or CurrentState.StringPropertyValue:
220 currentPropertyValue += current;
221 currentSymbol = JsonSymbol.Text;
222 break;
223 216 case CurrentState.ListValue:
224 217 currentPropertyValue += current;
225 218 currentSymbol = JsonSymbol.Text;
@@ -321,14 +314,9 @@ public class JsonNodeConverter(string jsonString)
321 314 return ValueType.Int;
322 315 }
323 316
324 if (long.TryParse(currentPropertyValue, out _))
325 {
326 return ValueType.Long;
327 }
328
329 return ValueType.None;
317 return long.TryParse(currentPropertyValue, out _) ? ValueType.Long : ValueType.None;
330 318 }
331 private static JsonPropertyNode? SummonJsonPropertyNode(ValueType currentValueType, int currentLayer, string currentPropertyName, string currentPropertyValue)
319 private static JsonPropertyNode SummonJsonPropertyNode(ValueType currentValueType, int currentLayer, string currentPropertyName, string currentPropertyValue)
332 320 {
333 321 var jsonPropertyNode = new JsonPropertyNode
334 322 {
@@ -351,7 +339,7 @@ public class JsonNodeConverter(string jsonString)
351 339 };
352 340 }
353 341
354 return jsonComplexPropertyNode.DescendingNodes.Find(node => node.PropertyName == nodeProperties[0]) is JsonNode jsonNode ? new(jsonNode) : null;
342 return jsonComplexPropertyNode.DescendingNodes.Find(node => node.PropertyName == nodeProperties[0]) is { } jsonNode ? new(jsonNode) : null;
355 343 }
356 344 }
357 345 enum CurrentState
Modified XFEExtension.NetCore/XFETransform/JsonConverter/NodeOperator.cs +7 -11
@@ -11,17 +11,13 @@ class NodeOperator
11 11 };
12 12 foreach (var node in jsonComplexPropertyNode.DescendingNodes)
13 13 {
14 if (node is JsonComplexPropertyNode complexPropertyNode)
15 {
16 valueNodes.Add([]);
17 foreach (var childNode in complexPropertyNode.DescendingNodes)
18 {
19 if (childNode is JsonPropertyNode jsonPropertyNode && nodeProperties.Contains(jsonPropertyNode.PropertyName))
20 {
21 valueNodes[^1].Add(jsonPropertyNode.PropertyName, new(jsonPropertyNode.Value, jsonPropertyNode.ValueType));
22 }
23 }
24 }
14 if (node is not JsonComplexPropertyNode complexPropertyNode)
15 continue;
16
17 valueNodes.Add([]);
18 foreach (var childNode in complexPropertyNode.DescendingNodes)
19 if (childNode is JsonPropertyNode jsonPropertyNode && nodeProperties.Contains(jsonPropertyNode.PropertyName))
20 valueNodes[^1].Add(jsonPropertyNode.PropertyName, new(jsonPropertyNode.Value, jsonPropertyNode.ValueType));
25 21 }
26 22 return selectableJsonNode;
27 23 }
Modified XFEExtension.NetCore/XFETransform/MultiEscapeConverter.cs +3 -13
@@ -18,15 +18,8 @@ public class MultiEscapeConverter
18 18 /// </summary>
19 19 /// <param name="str"></param>
20 20 /// <returns></returns>
21 public string Convert(string str)
22 {
23 str = ConvertEscapeSymbol(str);
24 foreach (var escape in Escapes)
25 {
26 str = str.Replace(escape, $"{EscapeSymbol}{escape}");
27 }
28 return str;
29 }
21 public string Convert(string str) => Escapes.Aggregate(ConvertEscapeSymbol(str), (current, escape) => current.Replace(escape, $"{EscapeSymbol}{escape}"));
22
30 23 /// <summary>
31 24 /// 逆转义(生成原文)
32 25 /// </summary>
@@ -34,10 +27,7 @@ public class MultiEscapeConverter
34 27 /// <returns></returns>
35 28 public string Inverse(string str)
36 29 {
37 foreach (var escape in Escapes)
38 {
39 str = str.Replace($"{EscapeSymbol}{escape}", escape);
40 }
30 str = Escapes.Aggregate(str, (current, escape) => current.Replace($"{EscapeSymbol}{escape}", escape));
41 31 str = InverseEscapeSymbol(str);
42 32 return str;
43 33 }
Modified XFEExtension.NetCore/XFETransform/StringConverter/ObjectAnalyzer.cs +8 -8
@@ -25,7 +25,7 @@ public class ObjectAnalyzer : StringConverter
25 25 {
26 26 outPutString += $"{AddObjectPlace(objectInfo)} {XFEConverter.OutPutTypeName(objectInfo.Type!)} {objectInfo.Name}:{objectInfo.Value}[{(int)objectInfo.Value}]\n";
27 27 }
28 else if (objectInfo.Value is string str && str == string.Empty)
28 else if (objectInfo.Value is "")
29 29 {
30 30 outPutString += $"{AddObjectPlace(objectInfo)} {XFEConverter.OutPutTypeName(objectInfo.Type!)} {objectInfo.Name}:string.Empty\n";
31 31 }
@@ -71,14 +71,14 @@ public class ObjectAnalyzer : StringConverter
71 71 {
72 72 tabString += "│ ";
73 73 }
74 if (objectInfo.SubObjects is not null)
75 {
76 if (objectInfo.SubObjects.Count > 0)
77 outPutString += OutPutSubObjects(objectInfo.SubObjects);
78 else
79 outPutString += $"{tabString}│ └─无内容";
80 74
81 }
75 if (objectInfo.SubObjects is null)
76 return outPutString;
77
78 if (objectInfo.SubObjects.Count > 0)
79 outPutString += OutPutSubObjects(objectInfo.SubObjects);
80 else
81 outPutString += $"{tabString}│ └─无内容";
82 82 }
83 83 }
84 84 return outPutString;
Modified XFEExtension.NetCore/XFETransform/XFEConverter.cs +23 -27
@@ -37,14 +37,7 @@ public class XFEConverter
37 37 if (IsBasicType(type))
38 38 return ConvertBasicTypeToCodeType(type.Name);
39 39 var genericArguments = type.GetGenericArguments();
40 if (genericArguments.Length == 0)
41 return type.Name;
42 return $"{type.Name.Replace($"`{genericArguments.Length}", string.Empty)}<{string.Join(", ", genericArguments.Select(x =>
43 {
44 if (IsBasicType(x))
45 return ConvertBasicTypeToCodeType(x.Name);
46 return OutPutTypeName(x);
47 }))}>";
40 return genericArguments.Length == 0 ? type.Name : $"{type.Name.Replace($"`{genericArguments.Length}", string.Empty)}<{string.Join(", ", genericArguments.Select(x => IsBasicType(x) ? ConvertBasicTypeToCodeType(x.Name) : OutPutTypeName(x)))}>";
48 41 }
49 42
50 43 /// <summary>
@@ -124,11 +117,12 @@ public class XFEConverter
124 117 {
125 118 arrayObjects.Add(GetObjectInfo(stringConverter, "数组成员", ObjectPlace.ArrayMember, layer + 1, currentFatherList, null, null, onlyProperty, onlyPublic, stopInThisLayer, maxLayer, maxArrayCount, currentFieldInfo, currentPropertyInfo));
126 119 }
127 if (currentCount > maxArrayCount && maxArrayCount != -1)
128 {
129 arrayObjects.Add(new ObjectInfoImpl(currentFieldInfo, currentPropertyInfo, stringConverter, name, objectPlace, layer, type, true, $"数组数量超出设定最大值({maxArrayCount})"));
130 break;
131 }
120
121 if (currentCount <= maxArrayCount || maxArrayCount == -1)
122 continue;
123
124 arrayObjects.Add(new ObjectInfoImpl(currentFieldInfo, currentPropertyInfo, stringConverter, name, objectPlace, layer, type, true, $"数组数量超出设定最大值({maxArrayCount})"));
125 break;
132 126 }
133 127 return new ObjectInfoImpl(currentFieldInfo, currentPropertyInfo, stringConverter, name, objectPlace, layer, type, false, true, value, arrayObjects);
134 128 }
@@ -148,11 +142,12 @@ public class XFEConverter
148 142 {
149 143 enumerableObjects.Add(GetObjectInfo(stringConverter, "列表成员", ObjectPlace.ListMember, layer + 1, currentFatherList, null, null, onlyProperty, onlyPublic, stopInThisLayer, maxLayer, maxArrayCount, currentFieldInfo, currentPropertyInfo));
150 144 }
151 if (currentCount > maxArrayCount && maxArrayCount != -1)
152 {
153 enumerableObjects.Add(new ObjectInfoImpl(currentFieldInfo, currentPropertyInfo, stringConverter, name, objectPlace, layer, type, true, $"列表数量超出设定最大值({maxArrayCount})"));
154 break;
155 }
145
146 if (currentCount <= maxArrayCount || maxArrayCount == -1)
147 continue;
148
149 enumerableObjects.Add(new ObjectInfoImpl(currentFieldInfo, currentPropertyInfo, stringConverter, name, objectPlace, layer, type, true, $"列表数量超出设定最大值({maxArrayCount})"));
150 break;
156 151 }
157 152 return new ObjectInfoImpl(currentFieldInfo, currentPropertyInfo, stringConverter, name, objectPlace, layer, type, false, true, value, enumerableObjects);
158 153 }
@@ -176,16 +171,17 @@ public class XFEConverter
176 171 }
177 172 continue;
178 173 }
179 if (!onlyProperty && memberInfo is FieldInfo fieldInfo)
174
175 if (onlyProperty || memberInfo is not FieldInfo fieldInfo)
176 continue;
177
178 try
179 {
180 subObjects.Add(GetObjectInfo(stringConverter, fieldInfo.Name, ObjectPlace.Field, layer + 1, currentFatherList, fieldInfo.FieldType, fieldInfo.GetValue(value), onlyProperty, onlyPublic, isType, maxLayer, maxArrayCount, fieldInfo));
181 }
182 catch
180 183 {
181 try
182 {
183 subObjects.Add(GetObjectInfo(stringConverter, fieldInfo.Name, ObjectPlace.Field, layer + 1, currentFatherList, fieldInfo.FieldType, fieldInfo.GetValue(value), onlyProperty, onlyPublic, isType, maxLayer, maxArrayCount, fieldInfo));
184 }
185 catch
186 {
187 subObjects.Add(GetObjectInfo(stringConverter, fieldInfo.Name, ObjectPlace.Property, layer + 1, currentFatherList, fieldInfo.FieldType, null, onlyProperty, onlyPublic, isType, maxLayer, maxArrayCount, fieldInfo));
188 }
184 subObjects.Add(GetObjectInfo(stringConverter, fieldInfo.Name, ObjectPlace.Property, layer + 1, currentFatherList, fieldInfo.FieldType, null, onlyProperty, onlyPublic, isType, maxLayer, maxArrayCount, fieldInfo));
189 185 }
190 186 }
191 187 return new ObjectInfoImpl(currentFieldInfo, currentPropertyInfo, stringConverter, name, objectPlace, layer, type, false, false, value, subObjects);
Modified XFEExtension.NetCore/XFETransform/XFEJsonTransformer.cs +18 -38
@@ -15,7 +15,7 @@ public static class XFEJsonTransformer
15 15 /// <param name="obj"></param>
16 16 /// <returns></returns>
17 17 /// <exception cref="XFEJsonTransformException">空对象异常</exception>
18 public static string? ConvertToJson(this object obj)
18 public static string? ConvertToJson(this object? obj)
19 19 {
20 20 if (obj is null)
21 21 {
@@ -56,22 +56,12 @@ public static class XFEJsonTransformer
56 56
57 57 private static string ConvertArrayOrEnumerableToJson(object obj)
58 58 {
59 if (obj is IEnumerable array)
60 {
61 var jsonElements = new List<string>();
59 if (obj is not IEnumerable array)
60 return string.Empty;
62 61
63 foreach (var item in array)
64 {
65 var json = item.ConvertToJson();
66 if (json is not null)
67 jsonElements.Add(json);
68 else
69 jsonElements.Add(string.Empty);
70 }
62 var jsonElements = (from object? item in array select item.ConvertToJson() into json select json ?? string.Empty).ToList();
71 63
72 return $"[{string.Join(",", jsonElements)}]";
73 }
74 return string.Empty;
64 return $"[{string.Join(",", jsonElements)}]";
75 65 }
76 66
77 67 private static string ConvertObjectToJson(object obj)
@@ -117,22 +107,18 @@ public static class XFEJsonTransformer
117 107 throw new ArgumentException("Json字符串为空");
118 108 }
119 109
120 var jsonObject = (T)Activator.CreateInstance(typeof(T))!;
110 var jsonObject = Activator.CreateInstance<T>()!;
121 111
122 112 var jsonProperties = GetJsonProperties(jsonString);
123 113 var objectType = typeof(T);
124 114
125 foreach (var jsonProperty in jsonProperties)
115 foreach ((string key, string propertyValue) in jsonProperties)
126 116 {
127 var propertyName = jsonProperty.Key;
128 var propertyValue = jsonProperty.Value;
129
130 var property = objectType.GetProperty(propertyName);
131 if (property is not null)
132 {
133 var convertedValue = ConvertToPropertyValue(propertyValue, property.PropertyType);
134 property.SetValue(jsonObject, convertedValue);
135 }
117 var property = objectType.GetProperty(key);
118 if (property is null)
119 continue;
120 var convertedValue = ConvertToPropertyValue(propertyValue, property.PropertyType);
121 property.SetValue(jsonObject, convertedValue);
136 122 }
137 123
138 124 return jsonObject;
@@ -147,13 +133,12 @@ public static class XFEJsonTransformer
147 133 foreach (var jsonToken in jsonTokens)
148 134 {
149 135 var propertyParts = jsonToken.Split(':');
150 if (propertyParts.Length == 2)
151 {
152 var propertyName = propertyParts[0].Trim('\"');
153 var propertyValue = propertyParts[1].Trim();
136 if (propertyParts.Length != 2)
137 continue;
138 var propertyName = propertyParts[0].Trim('\"');
139 var propertyValue = propertyParts[1].Trim();
154 140
155 jsonProperties[propertyName] = propertyValue;
156 }
141 jsonProperties[propertyName] = propertyValue;
157 142 }
158 143
159 144 return jsonProperties;
@@ -181,12 +166,7 @@ public static class XFEJsonTransformer
181 166 return DateTime.Parse(propertyValue.Trim('\"'));
182 167 }
183 168
184 if (targetType.IsEnum)
185 {
186 return Enum.Parse(targetType, propertyValue);
187 }
188
189 throw new NotSupportedException($"不支持的属性类型: {targetType.Name}");
169 return targetType.IsEnum ? Enum.Parse(targetType, propertyValue) : throw new NotSupportedException($"不支持的属性类型: {targetType.Name}");
190 170 }
191 171
192 172 #endregion
Modified XFEExtension.NetCore/XFPManager/XFFManager.cs +9 -27
@@ -13,25 +13,12 @@ public class XFFManager
13 13 /// <returns></returns>
14 14 public object? this[string name]
15 15 {
16 get
17 {
18 foreach (var field in Fields)
19 {
20 if (field.name == name)
21 {
22 return field.field;
23 }
24 }
25 return null;
26 }
16 get => (from field in Fields where field.Name == name select field.Field).FirstOrDefault();
27 17 set
28 18 {
29 foreach (var field in Fields)
19 foreach (var field in Fields.Where(field => field.Name == name))
30 20 {
31 if (field.name == name)
32 {
33 field.field = value;
34 }
21 field.Field = value;
35 22 }
36 23 }
37 24 }
@@ -43,13 +30,11 @@ public class XFFManager
43 30 /// <returns>字段值</returns>
44 31 public T? X<T>(string name)
45 32 {
46 foreach (var item in Fields)
33 foreach (var item in Fields.Where(item => item.Name == name))
47 34 {
48 if (item.name == name)
49 {
50 return item.field is null ? default : (T)item.field;
51 }
35 return item.Field is null ? default : (T)item.Field;
52 36 }
37
53 38 return default;
54 39 }
55 40 /// <summary>
@@ -59,12 +44,9 @@ public class XFFManager
59 44 /// <param name="value"></param>
60 45 public void E(string name, object value)
61 46 {
62 foreach (var item in Fields)
47 foreach (var item in Fields.Where(item => item.Name == name))
63 48 {
64 if (item.name == name)
65 {
66 item.field = value;
67 }
49 item.Field = value;
68 50 }
69 51 }
70 52 /// <summary>
@@ -83,7 +65,7 @@ public class XFFManager
83 65 Fields = [];
84 66 for (var i = 0; i < nameAndValue.Length; i += 2)
85 67 {
86 Fields.Add(new XField { name = nameAndValue[i].ToString(), field = nameAndValue[i + 1] });
68 Fields.Add(new XField { Name = nameAndValue[i].ToString(), Field = nameAndValue[i + 1] });
87 69 }
88 70 }
89 71 }
Modified XFEExtension.NetCore/XFPManager/XFManager.cs +15 -35
@@ -16,37 +16,22 @@ public class XFManager
16 16 {
17 17 get
18 18 {
19 foreach (var field in Fields)
19 foreach (var field in Fields.Where(field => field.Name == name))
20 20 {
21 if (field.name == name)
22 {
23 return field.field;
24 }
21 return field.Field;
25 22 }
26 foreach (var property in Properties)
27 {
28 if (property.Name == name)
29 {
30 return property.Property;
31 }
32 }
33 return null;
23 return (from property in Properties where property.Name == name select property.Property).FirstOrDefault();
34 24 }
35 25 set
36 26 {
37 foreach (var field in Fields)
27 foreach (var field in Fields.Where(field => field.Name == name))
38 28 {
39 if (field.name == name)
40 {
41 field.field = value;
42 }
29 field.Field = value;
43 30 }
44 foreach (var property in Properties)
31
32 foreach (var property in Properties.Where(property => property.Name == name))
45 33 {
46 if (property.Name == name)
47 {
48 property.Property = value;
49 }
34 property.Property = value;
50 35 }
51 36 }
52 37 }
@@ -58,13 +43,11 @@ public class XFManager
58 43 /// <returns></returns>
59 44 public T? X<T>(string name)
60 45 {
61 foreach (var item in Properties)
46 foreach (var item in Properties.Where(item => item.Name == name))
62 47 {
63 if (item.Name == name)
64 {
65 return (T?)item.Property;
66 }
48 return (T?)item.Property;
67 49 }
50
68 51 return default;
69 52 }
70 53 /// <summary>
@@ -74,12 +57,9 @@ public class XFManager
74 57 /// <param name="value"></param>
75 58 public void E(string name, object value)
76 59 {
77 foreach (var item in Properties)
60 foreach (var item in Properties.Where(item => item.Name == name))
78 61 {
79 if (item.Name == name)
80 {
81 item.Property = value;
82 }
62 item.Property = value;
83 63 }
84 64 }
85 65 /// <summary>
@@ -110,7 +90,7 @@ public class XFManager
110 90 {
111 91 for (var i = 0; i < nameAndValue.Length; i += 2)
112 92 {
113 Fields.Add(new XField { name = nameAndValue[i].ToString(), field = nameAndValue[i + 1] });
93 Fields.Add(new XField { Name = nameAndValue[i].ToString(), Field = nameAndValue[i + 1] });
114 94 }
115 95 }
116 96 }
@@ -124,7 +104,7 @@ public class XFManager
124 104 Fields = [];
125 105 for (var i = 0; i < nameAndValue.Length; i += 2)
126 106 {
127 Fields.Add(new XField { name = nameAndValue[i].ToString(), field = nameAndValue[i + 1] });
107 Fields.Add(new XField { Name = nameAndValue[i].ToString(), Field = nameAndValue[i + 1] });
128 108 }
129 109 }
130 110 }
Modified XFEExtension.NetCore/XFPManager/XFPManager.cs +8 -23
@@ -14,23 +14,13 @@ public class XFPManager
14 14 {
15 15 get
16 16 {
17 foreach (var property in Properties)
18 {
19 if (property.Name == name)
20 {
21 return property.Property;
22 }
23 }
24 return null;
17 return (from property in Properties where property.Name == name select property.Property).FirstOrDefault();
25 18 }
26 19 set
27 20 {
28 foreach (var property in Properties)
21 foreach (var property in Properties.Where(property => property.Name == name))
29 22 {
30 if (property.Name == name)
31 {
32 property.Property = value;
33 }
23 property.Property = value;
34 24 }
35 25 }
36 26 }
@@ -42,13 +32,11 @@ public class XFPManager
42 32 /// <returns>属性值</returns>
43 33 public T? X<T>(string name)
44 34 {
45 foreach (var item in Properties)
35 foreach (var item in Properties.Where(item => item.Name == name))
46 36 {
47 if (item.Name == name)
48 {
49 return (T?)item.Property;
50 }
37 return (T?)item.Property;
51 38 }
39
52 40 return default;
53 41 }
54 42 /// <summary>
@@ -58,12 +46,9 @@ public class XFPManager
58 46 /// <param name="value"></param>
59 47 public void E(string name, object value)
60 48 {
61 foreach (var item in Properties)
49 foreach (var item in Properties.Where(item => item.Name == name))
62 50 {
63 if (item.Name == name)
64 {
65 item.Property = value;
66 }
51 item.Property = value;
67 52 }
68 53 }
69 54 /// <summary>
Modified XFEExtension.NetCore/XFPManager/XField.cs +3 -3
@@ -2,6 +2,6 @@
2 2
3 3 internal class XField
4 4 {
5 public object? field;
6 public string? name;
7 }
5 public object? Field;
6 public string? Name;
7 }