From 5dfe3bbf0c927fe6fd1668faee1ae7ce4a152615 Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Tue, 15 Mar 2022 01:19:01 +1100 Subject: [PATCH] Fix missing and incorrect ctor caching - Shouldn't include ctors on abstract types - Missing parameterless ctors for structs (implicit) --- src/CacheObject/CacheMember.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/CacheObject/CacheMember.cs b/src/CacheObject/CacheMember.cs index b33c445..e8d04ba 100644 --- a/src/CacheObject/CacheMember.cs +++ b/src/CacheObject/CacheMember.cs @@ -187,11 +187,23 @@ namespace UnityExplorer.CacheObject if (!inspector.StaticOnly) flags |= BindingFlags.Instance; - // 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); + 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) {