【发布时间】:2018-02-08 15:30:18
【问题描述】:
我想为SerializedObject 写一个通用扩展方法,可以用来代替FindProperty,然后访问whateverValue 成员,所以我可以写so.Get<Bool>("myValue") 而不是so.FindProperty("myValue").boolValue。
如果模板专业化是 C# 中的一个东西,我想如何解决这个问题:
public static T Get<T>(this SerializedObject so, string name) {
Debug.LogError("Get called with unsuported type!");
}
public static bool Get<bool>(this SerializedObject so, string name) {
return so.FindProperty(name).boolValue;
}
如何在适当的 C# 中实现这样的目标?我也尝试添加一个System.Type 参数而不是专门化,但是这样的函数的返回类型应该是什么?
【问题讨论】:
标签: c# templates generics unity3d