Skip to main content

Questions tagged [extension-methods]

Methods that extend a given type, adding functionality to any instance of that type, even if the type in question is defined in a separate assembly. For example, a "Disemvowel" extension method could be written to add disemvoweling functionality to any "String" object.

2 votes
1 answer
107 views

Turn List<Either<A, B>> into Either<A, List<B>>

I'm trying to integrate Arrow-kt's Either into an application that needs to parse and validate filter input. This input is a comma separated list of criteria. ...
t3chb0t's user avatar
  • 44.3k
1 vote
1 answer
97 views

Take meal orders from breakfast, lunch and dinner menus

I have an exercise requires me to write a service to management menu. The requirement like this: Food menu includes: breakfast menu, lunch menu, dinner menu. The three menu haves list menu item( name, ...
David Moore's user avatar
2 votes
2 answers
2k views

Extension methods to modify an async Task's type from Task<IEnumerable<T>> to Task<List<T>>

I've written a lot of (await SomeTask).AsList(); in my project, and it's kind of annoying to keep wrapping it. To fix this I've written a little extension method on ...
Joost00719's user avatar
3 votes
1 answer
950 views

UIImage downscale and compression

getFinalImageData(:UIImage) takes a UIImage and downscales its size dimensions (to 400 ...
slushy's user avatar
  • 133
5 votes
4 answers
1k views

Naming a method that gets the next enum value or starts from the beginning if the given value is the last

I'm struggling to find a proper name for a specific method (in code named NameOfExtension), and would also like some feedback about its implementation. I am ...
c-chavez's user avatar
  • 153
2 votes
5 answers
435 views

Substring extension method with a method of removal

I consistently have code where I need to pull individual chunks of substrings out of a larger string; while I won't get into details, it's easy to replicate in a proof of concept: ...
Taco's user avatar
  • 949
0 votes
2 answers
671 views

Extension method to get the Sunday date from current date based on weekOffset

I want to write an extension method for getting Sunday Date based on weekOffset and current date. For example if weekOffset value is 1 that means next week sunday date and if weekOffset is 2 that ...
Coder's user avatar
  • 1
3 votes
1 answer
520 views

Extending method chaining IEnumerable with Add..If

I'm trying to write an extension (method chaining) for playing around a bit. What I made work is an extension to add an item to the list (what is pretty easy): ...
Matthias Burger's user avatar
1 vote
2 answers
87 views

Use proxy for jQuery-like DOM extensions

I have cleared all my scripting from the use of JQuery, but sometimes I miss a few handy extensions. Now I'm playing with the idea to "extend" ...
KooiInc's user avatar
  • 577
4 votes
3 answers
167 views

DistinctCount extension method

Here I go again. I have been finding a fairly common pattern in business logic code. And that pattern looks like this: ...
Jesse C. Slicer's user avatar
1 vote
1 answer
2k views

Pass class property as parameter to extension method

I have the following class structure: MyAttribute.cs ...
Igor's user avatar
  • 182
2 votes
1 answer
945 views

Programmatically getting the GUID of an application

Intrigued by the events chronicled here (also here and here), I saw the inherent utility in having a program-specific GUID available. The SO answers that were correct seemed a bit tightly-coupled and ...
Jesse C. Slicer's user avatar
2 votes
0 answers
343 views

Extension method: Task<T>.CoalesceAwait

There has been ongoing concern about the question of awaiting a task that could possibly be null, as when using null-coalescing operators. Consider the following: ...
Kyle Delaney's user avatar
2 votes
1 answer
1k views

Extension method for getting custom Principal Claim

I'm writing extension methods to shorten the code required to get custom Claims from an IPrincipal. I have two general forms for ...
Michael Brandon Morris's user avatar
18 votes
6 answers
6k views

Solving Fizz Buzz using LINQ in C#

The Fizz Buzz challenge is well-known and should not need any explanations, right? I recently got a bit bored and came up with a solution for Fizz Buzz using LINQ and even asynchronous code and a lot ...
Wim ten Brink's user avatar

15 30 50 per page
1
2 3 4 5
12