小编Chr*_*olf的帖子

C#无法反映到私人领域

我遇到了一个问题.

在Unity中,我想反思一个私人领域.但我总是为fieldinfo获取null.我究竟做错了什么?

public abstract class _SerializableType
{
    [SerializeField] private string name;
}

// because I am using a CustomPropertyDrawer for all inherited from _SerializeType
public class SerializableType<T> : _SerializableType { }
public class SerializableType : _SerializableType { }

[Serializable] public class CTech : SerializableType<_CouplingTechnology> { }
Run Code Online (Sandbox Code Playgroud)

所以使用这种方法实际上应该工作.

        // type is CTech
        // propertyPath in that case is "name"
        FieldInfo info = type.GetField(propertyPath, BindingFlags.Instance
                         | BindingFlags.Public | BindingFlags.NonPublic);
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

我在具有自己的CustomInspector的托管库中调用此方法.所以它反映到每个领域并计算如何显示它.AppDomain是完全信任的.我不知道还有什么可能是重要的......

c# reflection inheritance managed unity-game-engine

0
推荐指数
1
解决办法
314
查看次数

标签 统计

c# ×1

inheritance ×1

managed ×1

reflection ×1

unity-game-engine ×1