Model: Make Get*() return null instead of throwing exception if no matching item found
This commit is contained in:
@@ -43,10 +43,10 @@ namespace Il2CppInspector.Reflection
|
||||
}
|
||||
|
||||
// Get an assembly by its name
|
||||
public Assembly GetAssembly(string name) => Assemblies.First(a => a.FullName == name);
|
||||
public Assembly GetAssembly(string name) => Assemblies.FirstOrDefault(a => a.FullName == name);
|
||||
|
||||
// Get a type by its full name
|
||||
public TypeInfo GetType(string name) => Types.First(t => t.FullName == name);
|
||||
public TypeInfo GetType(string name) => Types.FirstOrDefault(t => t.FullName == name);
|
||||
|
||||
private TypeInfo getNewTypeUsage(Il2CppType usage, MemberTypes memberType) {
|
||||
switch (usage.type) {
|
||||
|
||||
@@ -82,13 +82,13 @@ namespace Il2CppInspector.Reflection {
|
||||
public List<PropertyInfo> DeclaredProperties { get; } = new List<PropertyInfo>();
|
||||
|
||||
// Get a field by its name
|
||||
public FieldInfo GetField(string name) => DeclaredFields.First(f => f.Name == name);
|
||||
public FieldInfo GetField(string name) => DeclaredFields.FirstOrDefault(f => f.Name == name);
|
||||
|
||||
// Get a method by its name
|
||||
public MethodInfo GetMethod(string name) => DeclaredMethods.First(m => m.Name == name);
|
||||
public MethodInfo GetMethod(string name) => DeclaredMethods.FirstOrDefault(m => m.Name == name);
|
||||
|
||||
// Get a property by its name
|
||||
public PropertyInfo GetProperty(string name) => DeclaredProperties.First(p => p.Name == name);
|
||||
public PropertyInfo GetProperty(string name) => DeclaredProperties.FirstOrDefault(p => p.Name == name);
|
||||
|
||||
// Method that the type is declared in if this is a type parameter of a generic method
|
||||
// TODO: Make a unit test from this: https://docs.microsoft.com/en-us/dotnet/api/system.type.declaringmethod?view=netframework-4.8
|
||||
|
||||
Reference in New Issue
Block a user