Tagged Questions

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

-1
votes
0answers
38 views

Class template specialization for implementing Automata [migrated]

I'm implementing classes for simulating and generating different kind of automata. I'd prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc. For a PDA a ...
5
votes
2answers
87 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 ...
5
votes
1answer
112 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
45 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
83 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
180 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
96 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
50 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
66 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... ...
2
votes
1answer
212 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
918 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
479 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
330 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
107 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
445 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 ...
5
votes
1answer
11k 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 ...
1
vote
1answer
428 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
1k 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
127 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 ...
0
votes
1answer
3k views

Java Fraction Class - Adding Together Two Objects [closed]

I'm currently working on a fraction class. I've successfully figured out how to create a fraction object as well as check for errors but I've blanked and cannot figure out how to add together the two ...
4
votes
2answers
325 views

Are private extension methods a bad thing to use?

In C# I have the following two extension methods. ...
1
vote
4answers
813 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
475 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
3k 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
106 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 ...
7
votes
2answers
734 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
311 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 ...
2
votes
2answers
30 views

Naming a method that filters or repeats elements as needed

I'm having trouble thinking of a good name for the following extension method: ...
0
votes
1answer
660 views

My own implementation of Linq SelectMany extension method

What do you think of my own implementation of the extension method SelectMany? Motivating criticism is always welcome. ...
2
votes
1answer
621 views

Clever way to build a extension method that ordenate my IQueryable<T>?

I want to create a ExtensionMethod to ordenate my linq query, called Ordenar. I'll sort it depending what columns is in ...
2
votes
4answers
374 views

60 helper methods in the same class

I have a pretty complex Java class with over 60 small helper methods used for easy readability and understanding. Just wondering, do you think having these many methods in a class could affect ...
2
votes
1answer
296 views

Cycle through an IEnumerable

I built an extension method to cycle through all items of an IEnumerable starting at some index: ...
7
votes
3answers
167 views

Evaluate my helper please

I have some static helper class: ...
6
votes
3answers
2k views

Grouping by sequence in LINQ

Suppose a series of objects (presented here as tuples): "a" | 1 "a" | 2 "b" | 3 "b" | 4 "a" | 5 There is no built in function (that I know of) to group by the first columns's sequence, that is, ...
5
votes
3answers
264 views

Javascript inheritance: is my solution correct?

I have been developing Javascript for few months, and, as a former Java developer, needed a simple way to perform class inheritance. My needs are: having private members not accessible ...
3
votes
3answers
202 views

Chained Assertions

Wouldn't it be nice to just chain assertions after a method call or is it just me? I was thinking that it'd improve readability. Instead of: ...
12
votes
1answer
13k views

Getting the value of a custom attribute from an enum

Suppose we have an enum called "Planet" and it has a custom attribute of class "PlanetAttr", these methods will give you the attribute value for a given Planet value: ...
3
votes
1answer
2k views

Convert .NET DateTime to a string using ordinals

With a DateTime object, it's easy to get, for example, 11 October 2011 by using: d.ToString("d MMMM yyyy"); However, there ...
1
vote
1answer
2k views

Creating Extension Method to map entity with subentities object to Poco object

I am trying to create an extension method that builds a POCO object (copies all the fields) for an Entity Object. When Entity object is simple (no navigation, no sub collections), it works fine. I ...
8
votes
7answers
1k views

Extension methods, is this too dirty?

I love lambdas, and functional programming etc. But sometimes I wonder if I take it too far.. ...
2
votes
4answers
630 views

Using an extension method for a small helper task that (ab)uses the fact that the object is not dereferenced

I've recently got into an habit where I've used extension methods for giving things fluent-like properties - such as the below example or as another example ...
8
votes
1answer
2k views

Small C++ Boost extension based on boost::property_tree

This is a small extension based on a boost::property_tree, which supports arbitrary values for the properties and appropriate serialization. It can be used as an ...
5
votes
2answers
3k views

Converting objects to type Bool

The following extension method is being used in our code base: ...
6
votes
3answers
341 views

Can you review my two extension methods?

...