C# extend method for Enum object

I am trying to create an extension method but can't get it to work.

So this works, create extension method on a Type of enum example:

public enum Pets
{
    ....
}

Above Pets can be extended creating an extension method like:

public static void Myex(this Pets pet)
{
    ... 
} 

But when I try to extend Enum itself example below:

Public static void something(this Enum en)
{
    ... 
} 

And try to use it like below

Enum.something(); 

this doesn't work.

I was trying to create similar method like Enum.Parse, Enum.IsDefined (which are already exposed by c#).

Jon Skeet
people
quotationmark

This has nothing to do with Enum as such - but extension methods "look" like they're instance methods. You can't "pretend" to add static methods, as it looks like you're currently trying to do.

You would be able to do:

Pets.SomeValue.something()

... because that's calling the extension method on an "instance" (a value). It will end up boxing the value, mind you.

people

See more on this question at Stackoverflow