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.

learn more… | top users | synonyms

3
votes
0answers
19 views

Making Dependency Property registration strongly typed

I've been working on another builder, this time for the DependencyProperty because it's object-based. This means that every ...
3
votes
3answers
67 views

Batch save with progress reporting

I reviewed this question that in my opinion uses a not so pretty batch-save so I tried improve it and this is what I came up with. In this more generic solution that allows to reuse it I wanted to ...
3
votes
1answer
56 views

Extracting complete lines from a data stream

When reading from the Console, it's very easy to get a complete line, you simply call Console.Readline. When reading from a ...
3
votes
1answer
78 views

ExceptionPrettifier for prettier exception strings

I've been refining my previous idea for pretty exception strings and made the following changes: Exceptions can be ordered. Prints all properties including Data. ...
4
votes
2answers
245 views

Automatic IEqualityComparer<T>

There are APIs like the Except extension that require the IEqualityComparer<T> to work. I find it's too much work for such ...
1
vote
1answer
67 views

Sequence to extend and forget

After receiving some feetback about my previous attempt to create reusable, easily extendable sequence generators I try once again to create such a framework. This time there is no inheritance. Just ...
3
votes
0answers
20 views

Extending Array to make a stack that bubbles unused objects up and active object down

Array.prototype.fastStack To combat GC and its impact on animation I created Array.fastStack that adds to the array prototype. It's a sort of stack that bubbles ...
2
votes
1answer
50 views

Extension methods to save and load form size, position, and state

I wrote these extension methods to provide a generic/re-usable method for saving a form's size, position, and window state. What I would primarily like to know is if there is a better way to handle ...
3
votes
1answer
212 views

Swift FloatingPoint rounded to places

I'm playing a bit with extensions for default protocols in Swift 3.0. I would like to implement rounded(toPlaces places: Int) -> Self for ...
0
votes
0answers
7 views

Presenting collections for code generation

I've never been too bothered by the lack of present (and thus print) support for Factor collections and other objects, but I've ...
4
votes
1answer
60 views

Credit card / IMEI check digit in Kotlin

I recently had the need to implement Luhn's Algorithm in a Java/Kotlin application. I needed a function that would add the check digit to the string of a number like a credit card or IMEI. It could be ...
0
votes
0answers
33 views

Bit twiddling utils for Int and Long classes

I added some bit twiddling utils to Int and Long classes in Scala but I have highly duplicated code. Is there a way to DRY this? ...
1
vote
0answers
136 views

HttpWebRequest Extension with cancelation and timeout support

I want to make a extension that extends HttpWebRequest in order to retrieve the response asynchronously. This is achieved by using the ...
6
votes
3answers
274 views

Checking whether relations are equal to foreign fields using LINQ Any()

Can you find a more understandable way to write the following one-liner? ...
3
votes
3answers
115 views

Custom struct design: Range

I had a need for some inventory management in a recent project. I decided to create a custom struct for managing the concept of a number range. It allows for easy navigation of a collection. It ...
2
votes
1answer
75 views

Extension methods to get direct reports from user

I have created a few extension methods to get the direct reports of a UserPrincipal as UserPrincipals themselves. This saves the ...
8
votes
5answers
129 views

Removing exact instances of elements in one list from another

Basically, here's the problem statement: Given an IEnumerable<T> source and an IEnumerable<T> exceptions, return ...
7
votes
1answer
195 views

Extension method splitting string on each capital letter

I'm creating my own game and for some statistics I need to get the names of specific objects. The problem was that I had them declared like "SmallFireBall" but I wanted them to appear like"Small Fire ...
2
votes
1answer
50 views

ExtensionMethods for iterating hierarchically data structures depth/breath-first

I wrote a few simple extension methods that allow to traverse a hierachically data structure depth-first or breath-first using LINQ: Usage: ...
5
votes
1answer
120 views

Validation extensions v2

I have still another version of my validation extensions. I've reworked it and added some new features. It doesn't relay on expression trees any more but as a compensation the same extensions can be ...
1
vote
1answer
126 views

Iterate through a 2D array. Kotlin extension method

Simple extension method for Kotlin. Should perform an action on every element in a 2d array. i.e. An array of arrays. I have made the assumption that because the receiver type is defined as an array ...
3
votes
1answer
92 views

Validation extensions

I've been working on another timesaver because I really really don't like to type all those validation ifs and exceptions over an over again. What I came up with ...
3
votes
1answer
75 views

Primitive Extensions - Replaces static primitive methods

I got annoyed having to do things like string.IsNullOrEmpty(myString) when it seemed as if myString.IsNullOrEmpty() would ...
2
votes
2answers
68 views

Custom map on `Array`

I have the following problem: Given an Array, apply a certain method x to each Array ...
0
votes
1answer
124 views

Data layer using extension methods

I've started to use extension methods to provide data layer functionality in our project. Our project is an MVC website using Code First Entity Framework. So, I've done things like this: ...
2
votes
1answer
167 views

XCTestCase#waitFalseExpectationUntilTimeout implementation

I am working on an iOS project and I'm in charge of testing most parts of it. As I write some tests, I often have the need to wait for an asynchronous method to finish, and then test that something ...
12
votes
2answers
175 views

Something like a LINQ provider

Ok, before you ask: yes, I need to do this. Sort of. I'm wrapping a 3rd-party API for data access, and I can't use an ORM, so I'm implementing this kind of thing: ...
5
votes
1answer
1k views

C# Extension Properties

I am doing some math - combining, reusing, extending different analyses methods over the same original data set. It would be reasonable to use C# extension methods in my case instead of defining ...
12
votes
2answers
1k views

Extension method to list enum values

I have the following enum extension method: ...
11
votes
5answers
606 views

Solving Project Euler Problem 1 using extension methods

As a self taught developer I never did any of the Project Euler problems, so I decided to just start with Problem 1 which states If we list all the natural numbers below 10 that are multiples of ...
1
vote
1answer
142 views

Variable length string validation against whitelisted characters

I need to validate a variable length string against some white-listed characters. The algorithm that I have works but I have a sneaking suspicion that there is a more elegant solution. The code below ...
3
votes
4answers
294 views

IEnumerable Extensions Linq AllOrDefault() Each()

I recently decided to try and write my own implementation of Linq, which then lead me on to trying to solve some of the problems we have in our code base at work. Our code is littered with the ...
3
votes
2answers
117 views

IEnumerable extension method that ingests SqlCommand and returns query results

The following ingests a preexisting SqlCommand and returns the values. A couple caveats right now. 1 ) Type properties must be named identical to the SQL column ...
6
votes
1answer
639 views

Helper for DropDownLists with extension method

Is the following helper idiomatic ASP.NET MVC? All the built-in DropDownListFor helpers only accept ...
5
votes
4answers
4k views

Get string truncated to max length

This is an extension method to get a string that is truncated to a maximum length. Any comments? ...
3
votes
2answers
316 views

Checking if an array is initialized and allocated in VB.NET

I am creating an add-in for a piece of software our company uses, so I'm working pretty extensively with that program's API. There are many COM object members which return or contain an array that I ...
2
votes
1answer
98 views

An extension method to get the current user [closed]

I think that everyone is familiar with the concept of a context (such as HttpContext in ASP.NET) where you can put some shared ...
3
votes
1answer
219 views

Extension method to do Linq Lookups

Does this extension method contain unnecessary work? - Thanks for reviewing Scenario - A series of tables are Key-Value pairs (Int "Id" / nvarChar "Title"). This extension method "dots-off" any ...
2
votes
1answer
394 views

String extension method that truncates at sentence punctuation

I've received a request at work and the senior developer is away on vacation so I can't ask him. The request was to truncate lengthy article titles while maintaining readability. In other words, don't ...
11
votes
2answers
391 views

Lazy String.Split

C#'s String.Split method comes from C# 2.0, and lazy operations weren't a feature back then. The task is to split a string according to a (single) separator. Doing ...
6
votes
3answers
310 views

Extension method to enumerate a hierarchical object

I have a domain object that I have no control over which itself contains a collection of this same type. This is a classical hierarichal representation like in a tree node hierarchy. I would like to ...
14
votes
1answer
2k views

Let's play some Swift Poker

Before you can do any sort of card game, you must first write some code to define your deck of cards. One thing I've noticed in looking at some of Apple's Swift interfaces is that they very much so ...
10
votes
1answer
411 views

Object to object mapping verification - is this extension method useful?

In our .NET tests we use NSubstitute & ExpectedObjects. Testing object expectations involves hand crafting large anonymous ...
5
votes
2answers
1k views

Extension methods for safely firing events

I wrote a set of extension methods for the EventHandler class that add the method Fire, which raises the event after creating a ...
7
votes
1answer
2k views

Extension methods for Daylight Savings Time dates

Just wondering if anyone had any suggestions for improvements. I created these extension methods so it's easier to get the start and end dates of Daylight Savings Time from the ...
2
votes
1answer
649 views

AsyncLazy disposal

I've made this extension method. Its purpose is to trigger the disposal of a value, stored in a Nito.AsyncEx AsyncLazy, as authored by @StephenCleary. Is this an ...
5
votes
2answers
575 views

Helper extension to release Windsor component; not sure if it's over-kill

One of the tenets of Windsor IoC (probably applies to all IoC containers too) is to "release what you explicitly resolve", which admittedly should occur rarely. But we have a fair few ...
4
votes
1answer
547 views

IndexOrDefault that functions like FirstOrDefault

I don't know why this is not in the .NET Library, but I need to be able to use an index against a list and not have it throw an exception if it is outside the bounds of the list. This is what I came ...
7
votes
2answers
107 views

Output in one window

Can anyone give me feedback please? I used what I have learnt so far, mainly methods, loops and arrays. I would like you view based on these topics, however, comments on how to improve are welcome. <...
2
votes
1answer
79 views

JavaScript mixins, extending and super methods

I've read a lot of stuff about mixins, inheritance and such, and in the end I came up with this solution for extending a class with multiple mixins. I haven't seen this anywhere else... Is this a ...