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.
1
vote
0answers
23 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:
...
4
votes
0answers
56 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 ...
0
votes
0answers
7 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
60 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
55 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
35 views
Custom map on `Array`
I have the following problem:
Given an Array, apply a certain method x to each Array ...
0
votes
1answer
77 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
45 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
149 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:
...
4
votes
1answer
172 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
619 views
11
votes
5answers
595 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
78 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
206 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
89 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
354 views
Helper for DropDownLists with extension method
Is the following helper idiomatic ASP.NET MVC? All the built-in DropDownListFor helpers only accept ...
4
votes
4answers
2k 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
268 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
82 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
175 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
279 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 ...
10
votes
2answers
323 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
256 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
371 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
509 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
450 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
495 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
106 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
74 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 ...
0
votes
1answer
203 views
JavaScript mixins - extending and super methods [closed]
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...
...
3
votes
1answer
4k views
Folder browser dialog to remember recent folder. Which method is better?
which of the following code you prefer and why?
The scenario is, I need to pass the recent folder path to folder browser dialog and if user selects any folder, need to save it back. The value is ...
5
votes
2answers
4k views
Extension method to return a default value for any null value
I'm creating an extension method that can be used on any type. The idea is that if this method is called, it checks if value is null. If null, it needs to return a default instance of the specified ...
4
votes
3answers
881 views
Lazy man's IEnumerable extension verification method
I often find myself doing this (or similar) with Lists and other collection types:
...
3
votes
1answer
1k views
Validating an entity using a dynamic list of predicates
I have a generic extension method for validating my entities. The main idea is to be able to specify at runtime (context related) the criteria for validating a specific entity (with the end goal of ...
4
votes
2answers
417 views
Get array of pressed buttons using extension method
In my game, I need to detect whether any buttons/keys are pressed at all before I try to process any input. This is easy enough for keys since the XNA library provides a ...
7
votes
3answers
584 views
Ternary extension method
I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup.
Is there a better way to write this ...
8
votes
1answer
36k views
Converting List to a DataTable and/or DataSet Extension Methods
Can someone help me improve this code? I and trying to have a couple extension methods to convert strongly-typed lists to a DataSet and ...
3
votes
1answer
2k views
A genric extension method to filter Linq-EF queries
I have various types of EF entities, all of them have a navigation property called "Employee". When generating reports the user will have the option to filter the report according to the different ...
8
votes
2answers
9k views
Digit to words converter
This is one of the longest programs I have made with methods and I think I must be doing this rather inefficiently. Any comments to improve would be appreciated.
...
6
votes
3answers
168 views
Object inheritance
I have written some example code to test object inheritance, but I'm not sure if it's really the best way for an object to inherit another's functions (like Java's ...
5
votes
3answers
645 views
Are private extension methods a bad thing to use?
In C# I have the following two extension methods.
...
1
vote
4answers
2k views
Extension Methods for Trimming List
I'm currently working on a project that I had to create basically a running queue of items. My thought was to do this by a list, but surprisingly there weren't any methods to remove the first sequence ...
2
votes
2answers
857 views
Extension methods for class Type
While working on one of my projects I actively used Reflection. While working with class Type I expected methods: TryGetMember, ...
5
votes
2answers
8k views
Extension methods for methods and properties that don't use non-public data
Generally speaking, I try and write my classes so they are highly cohesive.
Sometimes I have accessors (this problem isn't limited to accessors) which derive their value from non-public data only, ...
3
votes
2answers
126 views
improve the design of class “accuracy” in Python
I am learning about the class and methods in Python.
The class Accuracy is a class of several (13 in total) statistic values between a reference polygon and one or more segmented polygons based on ...
6
votes
2answers
2k views
Task.Finally extension, good, bad, or ugly?
I wrote this, and it has helped to avoid the 'Some exception weren't handled' problem. Is there something glaringly wrong with this that I might have missed?
...
7
votes
2answers
389 views
Synced/Atomic access
Forward
I would love any comments you have, any ideas, any flaws you can find, and any suggestions you might have regarding the code below.
If this is similar to other implementations, I would love ...