Why do all screen object methods need to be declared virtual?

80 views Asked by At

I've just started using white, and after successfully getting some tests working I am looking through some of the source to get a better understanding of how it all works.

One of the first things that caught me out (and keeps catching me out) is the need to have all public functions in a screen object be virtual. I have read through the documentation, and looked at the source, and I can't see any mention of why this requirement is mandatory... I can only think that the proxy enforces this requirement, but it seems to only operate on fields and doesn't seem to operate on any methods...

1

There are 1 answers

0
Stephen Jennings On BEST ANSWER

My guess is because White is using DynamicProxy to create proxy objects. DynamicProxy's website specifies:

You can use DynamicProxy to generate lightweight proxies on the fly for one or more interfaces or even concrete classes (but only virtual methods will be intercepted).

By marking properties and methods as virtual, the runtime will call methods on the proxy instead of calling methods on the class the proxy is based on.