Fix error when member is not found with string key during PDT interpretation.

This commit is contained in:
2023-04-08 13:34:37 +08:00
parent 916c55b4b2
commit 2221658e7a
2 changed files with 17 additions and 1 deletions

View File

@@ -90,6 +90,22 @@ namespace Cryville.Common {
return mil[0];
}
/// <summary>
/// Tries to get the member from a type with the specified name.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="name">The name of the member.</param>
/// <returns>The member. <see langword="null" /> when not found.</returns>
public static MemberInfo TryGetMember(Type type, string name) {
var mil = type.GetMember(
name,
MemberTypes.Field | MemberTypes.Property,
BindingFlags.Public | BindingFlags.Instance
);
if (mil.Length != 1) return null;
return mil[0];
}
/// <summary>
/// Gets the type of a member.
/// </summary>