tagged [extension-methods]
Impossible to use ref and out for first ("this") parameter in Extension methods?
Impossible to use ref and out for first ("this") parameter in Extension methods? Why is it forbidden to call `Extension Method` with `ref` modifier? This one is possible: And this one not: ``` public ...
- Modified
- 9 Feb at 11:8
Where do I put my extension method?
Where do I put my extension method? A senior member here gave me this code: ``` public static string Truncate(this string value, int maxChars) { return value.Length
- Modified
- 17 Jul at 16:32
In C#, what happens when you call an extension method on a null object?
In C#, what happens when you call an extension method on a null object? Does the method get called with a null value or does it give a null reference exception? ``` MyObject myObject = null; myObject....
- Modified
- 11 May at 08:47
What's your favorite LINQ to Objects operator which is not built-in?
What's your favorite LINQ to Objects operator which is not built-in? With extension methods, we can write handy LINQ operators which solve generic problems. I want to hear which methods or overloads y...
- Modified
- 5 Sep at 11:3
What is difference between extension method and static method?
What is difference between extension method and static method? What is the difference between an extension method and a static method ? I have two classes like this : and I can use these like ``` A
- Modified
- 2 Oct at 16:45
Elvis (?.) Extension Method in C# 5.0
Elvis (?.) Extension Method in C# 5.0 Is it possible to create some extension method in C# 5.0 to give the same results as the C# 6.0 Elvis (?.) operator? For example:
- Modified
- 29 May at 08:34
C# ambiguous extension methods
C# ambiguous extension methods LinqKit has an extension method `ForEach` for `IEnumerable` which clashes with `System.Collections.Generic.IEnumerable`. ``` Error 4 The call is ambiguous between the ...
- Modified
- 3 Nov at 20:23
Is it possible to create Extension Methods with 2.0 Framework?
Is it possible to create Extension Methods with 2.0 Framework? I was wondering if there is a way to create extension methods using Visual Studio 2005 and the 2.0 framework? If there is no way to do th...
- Modified
- 17 Feb at 13:4
Is it possible to extend arrays in C#?
Is it possible to extend arrays in C#? I'm used to add methods to external classes like IEnumerable. But can we extend Arrays in C#? I am planning to add a method to arrays that converts it to a IEnum...
- Modified
- 23 May at 12:18
How do I extend a class with c# extension methods?
How do I extend a class with c# extension methods? Can extension methods be applied to the class? For example, extend DateTime to include a Tomorrow() method that could be invoked like: I know I can u...
- Modified
- 26 Jan at 19:53
Extension Method for Generic Class
Extension Method for Generic Class > [C# -Generic Extension Method](https://stackoverflow.com/questions/1825952/c-generic-extension-method) [How do you write a C# Extension Method for a Generically ...
- Modified
- 23 May at 12:34
Extension Methods not Recognized
Extension Methods not Recognized What is necessary to have an extension method honored when it exists in an imported assembly? I built one in a class library project but it is not recognized in my web...
- Modified
- 5 Feb at 19:13
How do I ensure a sequence has a certain length?
How do I ensure a sequence has a certain length? I want to check that an `IEnumerable` contains one element. This snippet does work: However it's not very efficient, as `Count()` will enumerate the en...
- Modified
- 29 Sep at 13:46
Injecting DI service on a extension method
Injecting DI service on a extension method I'm trying to get the `IStringLocalizer` service instance inside a extension method, is it possible? Any suggestions on how should I inject it? My goal here ...
- Modified
- 15 Feb at 08:9
How to implement left join in JOIN Extension method
How to implement left join in JOIN Extension method I am trying to implement an outer join on this kind of query for the `p.Person` table. How would I do this? This example is taken from [http://ashis...
- Modified
- 22 Dec at 17:21
Extension Methods vs Static Utility Class
Extension Methods vs Static Utility Class I'm looking for some pros and cons for using extension methods over static utility classes in a C# app. For instance, a plus in the extension methods column i...
- Modified
- 20 Nov at 05:46
Enum from string, int, etc
Enum from string, int, etc Using extension method we can create methods to convert an enum to other datatype like string, int by creating extension methods `ToInt()`, `ToString()`, etc for the enum. I...
- Modified
- 18 Jan at 08:51
Extension method vs static method precedence
Extension method vs static method precedence Consider the following program: This fails to compile, with the error: > Member 'Test.A.Foo()' cannot be ac
- Modified
- 3 Jun at 14:42
Using reflection to check if a method is "Extension Method"
Using reflection to check if a method is "Extension Method" As part of my application I have a function that receives a MethodInfo and need to do specific operations on it depending if that method is ...
- Modified
- 6 Apr at 14:52
C#: Adding extension methods to a base class so that they appear in derived classes
C#: Adding extension methods to a base class so that they appear in derived classes I currently have an extension method on System.Windows.Forms.Control like this: However, this method doesn't appear ...
- Modified
- 1 Aug at 22:11
Why can you not invoke extension methods directly?
Why can you not invoke extension methods directly? Can someone explain to me why in the following the 3rd invocation of DoSomething is invalid? ( Error message is "The name 'DoSomething' does not exis...
- Modified
- 11 Oct at 12:29
What's the Best Way to Add One Item to an IEnumerable<T>?
What's the Best Way to Add One Item to an IEnumerable? Here's how I would add one item to an IEnumerable object: This is awkward. I don't see a method called something like `ConcatSingle()` however. I...
- Modified
- 6 Mar at 15:26
Extension Methods - IsNull and IsNotNull, good or bad use?
Extension Methods - IsNull and IsNotNull, good or bad use? I like readability. So, I came up with an extension mothod a few minutes ago for the (x =! null) type syntax, called IsNotNull. Inversly, I a...
- Modified
- 29 Sep at 21:39
Using extension methods defined in C# from F# code
Using extension methods defined in C# from F# code I have a series of extension methods defined for various classes in a C# library. I'm currently writing some F# code and instead of rewriting that co...
- Modified
- 23 Apr at 11:6
How to make dictionary extension-methods?
How to make dictionary extension-methods? I'm trying to write a `Dictionary` extension that works independently of the data types of Key/Value. I tried pass it by using the `object` data type, assumin...
- Modified
- 10 May at 21:23