摩尔和静态场
从我能够找到的,Moles不处理静态构造函数。这同样适用于静态字段吗?我一直在试图捣毁一个"初始化"的课程。通过静态字段。
From what I've been able to find, Moles doesn't handle static constructors. Does the same apply to static fields? I keep getting errors trying to mole out a class thats "initalized" by a static field.
ie
public class SomeClass
{
static public SomeClass Current = new SomeClass();
public OtherClass foo; // this lazy loads
}
执行SomeClass.Current.foo.bar()抛出无论我是否重定向foo.bar()做其他事情,SomeClass的类型 初始化异常。
Doing SomeClass.Current.foo.bar() throws a type initialization exception for SomeClass regardless if I've redirected foo.bar() to do something else.
请参阅参考手册中的[MolesEraseStaticConstructor]属性:
Take a look at the [MolesEraseStaticConstructor] attribute, also in the reference manual:
http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf
通过擦除静态构造函数,您还会擦除所有静态字段初始化。
By erasing a static constructor, you also erase all static field initializations.