Best practise for overriding static classes
Posted
by maxp
on Stack Overflow
See other posts from Stack Overflow
or by maxp
Published on 2010-05-25T08:59:33Z
Indexed on
2010/05/25
9:31 UTC
Read the original article
Hit count: 301
As it is not possible to override a static class in c#, if i want to override a method I generally define a delegate matching the signature of the static method, then modify the method along the lines of:
public static void foo(int bar)
{
if (delegatename!=null)
{
delegatename.Invoke(bar);
}
else
{
//execute previous code as normal
}
}
I feel a twinge of guilt, knowing this is a bit messy.
Can anyone suggest a neater solution to this problem (other than rewriting the original structure)
© Stack Overflow or respective owner