Fix missing and incorrect ctor caching

- Shouldn't include ctors on abstract types
- Missing parameterless ctors for structs (implicit)
This commit is contained in:
Sinai 2022-03-15 01:19:01 +11:00
parent dc81451ce5
commit 5dfe3bbf0c

View File

@ -187,12 +187,24 @@ namespace UnityExplorer.CacheObject
if (!inspector.StaticOnly)
flags |= BindingFlags.Instance;
if (!type.IsAbstract)
{
// Get non-static constructors of the main type.
// There's no reason to get the static cctor, it will be invoked when we inspect the class.
// Also no point getting ctors on inherited types.
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
// structs always have a parameterless constructor
if (type.IsValueType)
{
CacheConstructor cached = new(type);
cached.SetFallbackType(type);
cached.SetInspectorOwner(inspector, null);
ctors.Add(cached);
}
}
foreach (var declaringType in types)
{
var target = inspectorTarget;