Vinccool96
Vinccool96

Reputation: 268

What is the convention for naming C# files that contain extension methods?

While creating a library to learn C#, I've realized that there are a lot of conventions on how to name files, variables, parameters, interfaces, etc.

Now, I am making a file that will contain extension methods, and thus was left wondering if there are any convention on how to name those files? Is there anything suggested by the community, even if non-official?

While looking at the page about extension methods and the one about how to implement them, I realized that the name of the file used are not mentioned. I don't know if it's a coincidence.

Upvotes: 1

Views: 528

Answers (1)

Guru Stron
Guru Stron

Reputation: 142903

There is no defined convention (at least that I know of). It is not mentioned in the code style doc and I don't see anything in the configurable naming rules.

Usual approach I've seen is to group extension methods by type they extend (or some logical concept) and give it suffix like Extensions/Exts/Ext:

public static class FooExtensions
{
    public static int CountBar(this Foo foo) => 1;
}

For example framework classes and Microsoft developed libraries (like EF Core) seems to favor use of the Extensions suffix:

Though there are counter-examples like Enumerable and Queryable static classes containing LINQ extension methods.

Upvotes: 2

Related Questions