Can I replace (or override) a class definition with one of my own implementation?
Explanation:
- I have a class with a System.Random instance, and I am trying to test it without modifying its original code...
- So I am planning to replace Random class with one of my own implementation, that allows controlling generated sequence.. Please see this question.
`
class foo
{
Random r=new Random();
double bar()
{
double ans=r.NextDouble();
.....// evaluate ans
return ans;
}
}
`
What are the possible ways that I can replace implementation of Random class with another one without changing (or with minimum changes) the original code file??
Edit:
One solution is to inherit Random class and modify it... but that requires changing each Random instance with the inherited one... I do not want to modify the code, because I am just testing it!!
Edit 2:
Can I say in C#: "Each Random class in this file is MyNamespace.Random not System.Random" ??
IRandom { double NextDouble(); }interface into theSystem.Randomtype and abstract it in our code.