Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 5dfe3bb

Browse files
committed
Fix missing and incorrect ctor caching
- Shouldn't include ctors on abstract types - Missing parameterless ctors for structs (implicit)
1 parent dc81451 commit 5dfe3bb

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/CacheObject/CacheMember.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,23 @@ public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type typ
187187
if (!inspector.StaticOnly)
188188
flags |= BindingFlags.Instance;
189189

190-
// Get non-static constructors of the main type.
191-
// There's no reason to get the static cctor, it will be invoked when we inspect the class.
192-
// Also no point getting ctors on inherited types.
193-
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
194-
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
190+
if (!type.IsAbstract)
191+
{
192+
// Get non-static constructors of the main type.
193+
// There's no reason to get the static cctor, it will be invoked when we inspect the class.
194+
// Also no point getting ctors on inherited types.
195+
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
196+
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
197+
198+
// structs always have a parameterless constructor
199+
if (type.IsValueType)
200+
{
201+
CacheConstructor cached = new(type);
202+
cached.SetFallbackType(type);
203+
cached.SetInspectorOwner(inspector, null);
204+
ctors.Add(cached);
205+
}
206+
}
195207

196208
foreach (var declaringType in types)
197209
{

0 commit comments

Comments
 (0)