mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-15 22:07:48 +08:00
Fix missing and incorrect ctor caching
- Shouldn't include ctors on abstract types - Missing parameterless ctors for structs (implicit)
This commit is contained in:
parent
dc81451ce5
commit
5dfe3bbf0c
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user