MoledTypeAttribute on specific type generates moles and stubs for all types in the target type's assembly

178 views Asked by At

I was hoping that, e.g., [assembly: MoledType(typeof(System.DateTime))] would only generate an mscorlib.Moles assembly with System.Moles.MDateTime, but the generated assembly contains all the types in mscorlib moled. Is this normal or documented behavior (I couldn't find an answer in http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf)?

2

There are 2 answers

1
Mike Christian On

Yes, this is expected functionality. The mscorlib is pre-compiled. Before the pre-compile was shipped, the first Moles compile took a very long time. A fast compile time was traded for the inability to selectively mole framework types. Because the mole assembly is basically a giant wrapper filled with Func calls to mscorlib, providing framework-wide coverage contributes very little overhead to performance, and is therefore an acceptable trade.

0
Dave Fancher On

You can generally supply a number of filter options in the .moles file (mscorlib being an exception as you've found and Mike mentioned). For example, you can disable stub or mole type generation altogether with the StubGeneration or MoleGeneration elements respectively. For more control you can also use the Types element with a combination of Add, Remove, and Clear elements.

The Moles reference manual goes into some detail about filtering stub types on pages 12 and 13. Unfortunately it makes no mention of filtering Mole types but the process is basically the same.