返回提交历史
Modified
XFEExtension.NetCore.WinUIHelper/Utilities/Helper/ProfileHelper.cs
+3
-3
Modified
XFEExtension.NetCore.WinUIHelper/XFEExtension.NetCore.WinUIHelper.csproj
+7
-2
XFEstudio/XFEExtension.NetCore.WinUIHelper
优化 ProfileHelper 类型获取逻辑
在 `ProfileHelper.cs` 文件中,将类型获取方式从 `Type.GetType` 修改为 `Assembly.GetEntryAssembly()?.GetType`,增强了类型查找的安全性。同时,改进了错误处理逻辑,确保在未找到类型或属性时返回默认值,而不是抛出异常。
411c4c4
代码差异
2 个文件
+10
-5
@@ -20,7 +20,7 @@ public static class ProfileHelper
20
20
throw new ArgumentException("Invalid property path. It should be in the format 'NameSpace.ClassName.PropertyName'.");
21
21
string[] className = splitPath[..^1];
22
22
var propertyName = splitPath[^1];
23
var type = Type.GetType(string.Join(".", className)) ?? throw new ArgumentException($"Type '{className}' not found.");
23
var type = Assembly.GetEntryAssembly()?.GetType(string.Join(".", className)) ?? throw new ArgumentException($"Type '{className}' not found.");
24
24
var propertyInfo = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public) ?? throw new ArgumentException($"Property '{propertyName}' not found on type '{className}'.");
25
25
if (value is not null && !propertyInfo.PropertyType.IsAssignableFrom(value.GetType()))
26
26
throw new ArgumentException($"Value is not assignable to property '{propertyName}' of type '{propertyInfo.PropertyType}'.");
@@ -39,7 +39,7 @@ public static class ProfileHelper
39
39
return default;
40
40
string[] className = splitPath[..^1];
41
41
var propertyName = splitPath[^1];
42
var type = Type.GetType(string.Join(".", className));
42
var type = Assembly.GetEntryAssembly()?.GetType(string.Join(".", className));
43
43
if (type is null)
44
44
return default;
45
45
var propertyInfo = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public);
@@ -61,7 +61,7 @@ public static class ProfileHelper
61
61
return default;
62
62
string[] className = splitPath[..^1];
63
63
var propertyName = splitPath[^1];
64
var type = Type.GetType(string.Join(".", className));
64
var type = Assembly.GetEntryAssembly()?.GetType(string.Join(".", className));
65
65
if (type is null)
66
66
return default;
67
67
var propertyInfo = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public);
@@ -9,14 +9,19 @@
9
9
<Nullable>enable</Nullable>
10
10
<GenerateDocumentationFile>True</GenerateDocumentationFile>
11
11
<Title>XFEExtension.NetCore.WinUIHelper</Title>
12
<Version>1.0.5</Version>
12
<Version>1.0.6</Version>
13
13
<Authors>XFEstudio</Authors>
14
14
<PackageIcon>logoIcon.png</PackageIcon>
15
15
<Description>WinUI的各种工具类,帮助开发者快速构建一个模块化的WinUI项目</Description>
16
16
<Copyright>寰宇朽力网络科技有限公司版权所有</Copyright>
17
17
<NeutralLanguage>zh-CN</NeutralLanguage>
18
18
<PackageReadmeFile>README.md</PackageReadmeFile>
19
<PackageReleaseNotes>修复AppPathHelper中的应用程序名称问题</PackageReleaseNotes>
19
<PackageReleaseNotes>
20
优化 ProfileHelper 类型获取逻辑
21
22
在 `ProfileHelper.cs` 文件中,将类型获取方式从 `Type.GetType` 修改为 `Assembly.GetEntryAssembly()?.GetType`,增强了类型查找的安全性。同时,改进了错误处理逻辑,确保在未找到类型或属性时返回默认值,而不是抛出异常。
23
24
</PackageReleaseNotes>
20
25
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
21
26
<PackageProjectUrl>https://github.com/XFEstudio/XFEExtension.NetCore.WinUIHelper</PackageProjectUrl>
22
27
<RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.WinUIHelper.git</RepositoryUrl>