I think you can achieve this functionality using Extensions method. This functionality is added since
C#3[
^]. For example, the following class will extend an
int
datatype instances to have a functionality called HasValueOtherThanZero.
public static class IntegerExtension
{
public static bool HasValueOtherThanZero(this int myNumber)
{
if (myNumber != null && myNumber > 0)
return true;
return false;
}
}
So when ever you instantiate an integer variable, this functionality will appear after "." called.
static void Main(string[] args)
{
int x = 20;
if (x.HasValueOtherThanZero()) {
}
}
I hope this might help you well.