U:调整所有代码格式
This commit is contained in:
1 parent
d133bacf55
commit
155b67e831
342 files changed
+9431
-9868
No files matched your search
@@ -186,19 +186,13 @@ public class ReflectionHelperTests
|
||||
|
||||
// Act: 使用 ReflectionHelper(有缓存)
|
||||
var sw1 = System.Diagnostics.Stopwatch.StartNew();
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
_ = ReflectionHelper.GetPropertyValue(user, nameof(User.Name));
|
||||
}
|
||||
for (var i = 0; i < iterations; i++) _ = ReflectionHelper.GetPropertyValue(user, nameof(User.Name));
|
||||
sw1.Stop();
|
||||
|
||||
// Act: 使用原生反射(无缓存)
|
||||
var propertyInfo = typeof(User).GetProperty(nameof(User.Name))!;
|
||||
var sw2 = System.Diagnostics.Stopwatch.StartNew();
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
_ = propertyInfo.GetValue(user);
|
||||
}
|
||||
for (var i = 0; i < iterations; i++) _ = propertyInfo.GetValue(user);
|
||||
sw2.Stop();
|
||||
|
||||
// Assert: ReflectionHelper 应该比直接反射快(由于缓存和表达式树)
|
||||
@@ -377,7 +371,7 @@ public class ReflectionHelperTests
|
||||
var target = new UserDto();
|
||||
|
||||
// Act
|
||||
ReflectionHelper.CopyProperties(source, target, ignoreCase: true);
|
||||
ReflectionHelper.CopyProperties(source, target, true);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Alice", target.Name);
|
||||
@@ -565,12 +559,8 @@ public class ReflectionHelperTests
|
||||
|
||||
// Act: 实例化并执行插件
|
||||
foreach (var pluginType in plugins)
|
||||
{
|
||||
if (ReflectionHelper.CreateInstance(pluginType) is ITestService plugin)
|
||||
{
|
||||
plugin.Execute(); // 输出:Executing test service
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -610,9 +600,7 @@ public class ReflectionHelperTests
|
||||
|
||||
// Act: 动态更新属性
|
||||
foreach (var (propertyName, value) in propertyUpdates)
|
||||
{
|
||||
ReflectionHelper.SetPropertyValue(user, propertyName, value);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Updated Bob", user.Name);
|
||||
@@ -631,10 +619,7 @@ public class ReflectionHelperTests
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var description = ReflectionHelper.GetAttribute<System.ComponentModel.DescriptionAttribute>(property);
|
||||
if (description != null)
|
||||
{
|
||||
validationMessages[property.Name] = $"{description.Description}不能为空";
|
||||
}
|
||||
if (description != null) validationMessages[property.Name] = $"{description.Description}不能为空";
|
||||
}
|
||||
|
||||
// Assert
|
||||
@@ -671,4 +656,4 @@ public class ReflectionHelperTests
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user