views:

31

answers:

1

Hi. I am trying to make a class helper for the Color class in C#. I am a Delphi programmer and as far as I know, class helpers allow you to expand base classes so when you create an instance of the base class, you have access not only to the base methods, but also to all those defined in the helper class. Is it possible to achieve a similar effect in C#? Let's say, I have the following static method:

public static Color AdjustForeColor(Color backColor)
{
  double mediumColor = ((0.3 * 255.0) + (0.59 * 255.0) + (0.11 * 255.0)) / 2.0;
  if ((0.3 * backColor.R) + (0.59 * backColor.G) + (0.11 * backColor.B) > mediumColor)
    return Color.Black;
  else
    return Color.White;
}

It adjusts the font colour to the background so that it stays readable. I would like this method to be accessible through the Color class (Color.AdjustForeColor()). How to do that?

Thanks in advance.

Mariusz.

+2  A: 

It is called extension methods in C#

idstam