Questions tagged [extension-method]
The extension-method tag has no summary.
22 questions
1 vote
2 answers
309 views
Wrapping Business Logic In Extension Methods For POCOs
I have recently stumbled upon a use case of extension methods and wanted to gather some design thoughts. The problem: A IEnumerable of a POCO and within that list there should exist a POCO that ...
2 votes
0 answers
67 views
What is the idiomatic Swift way to add general functionality via protocol/extension?
I am a scala developer new to swift. In scala we can share implementation across a variety of classes by "extending" a trait that has default implementations for the methods. I would like to see how ...
4 votes
1 answer
2k views
Why is it bad to map between a Model and a ViewModel in an extension method
In a recent Pull Request (PR) of mine, a colleague suggested that it was a bad idea to map between a model and its view model via extension methods. I asked why and he said: It isn't how extension ...
6 votes
4 answers
3k views
Replacing Linq Methods with Extension Methods
So, I've fallen into the fad trap, and started replacing a large amount of linq queries with extension methods. For example: orders.Where(o => o.Status == ShippedStatus.Shipped).Select(o => o....
0 votes
3 answers
243 views
Should I reuse a predicate for multiple IEnumerable checks
In a long running Windows Service I have a custom thread pool manager that has a loop which continuously looks through a couple lists for idle threads. Given multiple uses of the same predicate, is ...
0 votes
3 answers
750 views
When it isn't right to add types to a well known namespace?
For the purpose of writing a library, I found to be nice to add types to some well known namespace. Example: I've written a couple of extension methods for BinaryWriter and naturally put them in ...
2 votes
1 answer
2k views
Design Pattern for Library Wrapping Extern Methods
I am working to create a C# library that wraps a C DLL to integrate with our test system. The C DLL has probably close to 100 functions that can be accessed and all from the same DLL. I don't need ...
1 vote
1 answer
344 views
Does merely parameterizing a dependency meet the requirements for Inversion of Control?
When I find a concrete dependency inside an extension method, I have been attempting to remove the (concrete) dependency by parameterising it like so // original implementation public static List<...