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.
                178 questions
            
            
            
                6
            
            votes
        
        
            
                3
            
            answers
        
        
            
                451
            
            views
        
        
            
            
            
        `repeat_and_join` function for strings and chars in rust
                    Background
I'm trying to write a helper function for constructing repeating strings with a separator.
...
                
            
       
        
            
                4
            
            votes
        
        
            
                2
            
            answers
        
        
            
                213
            
            views
        
        
            
            
        Swift String-extension 'countOccurrencesOfChar'
                    Loosely inspired by Ruby's String.count-method I wrote a similar Swift-method myself as an extension to the String-class. Then I had the idea to use a second parameter with which you can control if ...
                
            
       
        
            
                4
            
            votes
        
        
            
                1
            
            answer
        
        
            
                144
            
            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. ...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                135
            
            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, ...
                
            
       
        
            
                3
            
            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 ...
                
            
       
        
            
                3
            
            votes
        
        
            
                1
            
            answer
        
        
            
                991
            
            views
        
        
            
            
        UIImage downscale and compression
                    getFinalImageData(:UIImage) takes a UIImage and downscales its size dimensions (to 400 ...
                
            
       
        
            
                6
            
            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 ...
                
            
       
        
            
                2
            
            votes
        
        
            
                5
            
            answers
        
        
            
                485
            
            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:
...
                
            
       
        
            
                0
            
            votes
        
        
            
                2
            
            answers
        
        
            
                779
            
            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 ...
                
            
       
        
            
                3
            
            votes
        
        
            
                1
            
            answer
        
        
            
                558
            
            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):
...
                
            
       
        
            
                1
            
            vote
        
        
            
                2
            
            answers
        
        
            
                129
            
            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" ...
                
            
       
        
            
                4
            
            votes
        
        
            
                3
            
            answers
        
        
            
                214
            
            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: ...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                2k
            
            views
        
        
            
            
            
        Pass class property as parameter to extension method
                    I have the following class structure:
MyAttribute.cs
...
                
            
       
        
            
                2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                1k
            
            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 ...
                
            
       
        
            
                2
            
            votes
        
        
            
                0
            
            answers
        
        
            
                369
            
            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:
...
                
            
       
         
         
         
         
         
         
         
         
        