摩尔和静态场 [英] Moles and Static fields

查看:88
本文介绍了摩尔和静态场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我能够找到的,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.


这篇关于摩尔和静态场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆