mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 06:08:16 +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)
|
if (!inspector.StaticOnly)
|
||||||
flags |= BindingFlags.Instance;
|
flags |= BindingFlags.Instance;
|
||||||
|
|
||||||
// Get non-static constructors of the main type.
|
if (!type.IsAbstract)
|
||||||
// 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.
|
// Get non-static constructors of the main type.
|
||||||
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
// There's no reason to get the static cctor, it will be invoked when we inspect the class.
|
||||||
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
|
// 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)
|
foreach (var declaringType in types)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user