This is an add-in for Fody
Change all members to virtual
as part of your build.
https://nuget.org/packages/Virtuosity.Fody/
PM> Install-Package Virtuosity.Fody
- from non
sealed
classes - non
static
members - non
abstract
members - non
private
members - non
virtual
members
- change calls to those members to
virtual
- change
new
modifiers tooverride
modifiers
If for some reason you want to skip a specific class you can mark it with a DoNotVirtualizeAttribute
.
Since no reference assembly is shipped with Virtuosity. Just add the below class to your assembly. Namespace does not matter.
public class DoNotVirtualizeAttribute : Attribute
{
}
So your class will look like this
[DoNotVirtualize]
public class ClassToSkip
{
...
}
These config options are access by modifying the Virtuosity
node in FodyWeavers.xml
A list of namespaces to exclude.
Can not be defined with IncludeNamespaces
.
Can take two forms.
As an element with items delimited by a newline.
<Virtuosity>
<ExcludeNamespaces>
Foo
Bar
</ExcludeNamespaces>
</Virtuosity>
Or as a attribute with items delimited by a pipe |
.
<Virtuosity ExcludeNamespaces='Foo|Bar'/>
A list of namespaces to include.
Can not be defined with ExcludeNamespaces
.
Can take two forms.
As an element with items delimited by a newline.
<Virtuosity>
<IncludeNamespaces>
Foo
Bar
</IncludeNamespaces>
</Virtuosity>
Or as a attribute with items delimited by a pipe |
.
<Virtuosity IncludeNamespaces='Foo|Bar'/>
If you are coding in .net you will have used or heard of one of the following tools
Well all these tools make use of DynamicProxy. DynamicProxy allows for runtime interception of members. The one caveat is that all intercepted members must be virtual. This means that that all the above tools, to some extent, require members to be virtual.
- [http://msdn.microsoft.com/en-us/library/gg715120(v=vs.103).aspx] "One of the requirements for lazy loading proxy creation is that the navigation properties must be declared virtual"
- Must Everything Be Virtual With NHibernate?
- RhinoMocks Why methods need to be declared virtual
- [http://groups.google.com/group/moqdisc/browse_thread/thread/2e02e367d017f274 Moq My method needs to be virtual?]
- "NMock supports mocking of classes with virtual methods"
- Ninject Important Note:Your methods/properties to be intercepted must be virtual!
- NSubstitute:Some operations on non virtual members should throw an exception
If you forget to mark something as virtual these tools will not work and fail in sometimes very unhelpful ways. So rather than having to remember to use the virtual keyword Virtuosity means members will be virtual by default.
Russian Doll designed by Simon Child from The Noun Project