【发布时间】:2017-01-31 04:18:01
【问题描述】:
是否可以使用 Cecil 将字段替换为属性?具体来说:
// Replace this.
public static readonly Something Thing = new Something(...);
// With this.
private static readonly Something _Thing = new Something(...);
public static Something Thing
{
get
{
// My goal is to insert some extra code here, which I can't do if it's a field.
return _Thing;
}
}
如果可能的话,它可以有效地完成吗? IE。然后我是否需要遍历每个引用程序集中每种类型中的每个方法,以调用属性的 get_Thing 来替换 Thing 的每个实例?
如果我可以让用户写 public static Something Thing { get; } = new Something(...); 这样它已经是一个属性会容易得多,但我不能因为 Unity 的编译器不支持属性初始化器。
注意:我对使用 IL 几乎一无所知。
【问题讨论】:
标签: c# unity3d mono mono.cecil