Reputation: 268
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
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:
EntityFrameworkQueryableExtensions
- Entity Framework LINQ related extension methods.EndpointRouteBuilderExtensions
- Provides extension methods for IEndpointRouteBuilder
to add endpoints.MemoryExtensions
- Provides extension methods for the memory-related and span-related types, such as Memory<T>
, ReadOnlyMemory<T>
, Span<T>
, and ReadOnlySpan<T>
.Though there are counter-examples like Enumerable
and Queryable
static classes containing LINQ extension methods.
Upvotes: 2