By tag: ExtensionMethods
0
kicks
Another C# trick: Fluents, Inheritance and Extension Methods
Here’s a scenario which Damien and I encountered recently.
We needed a way of specifying Facets for properties on Entities, i.e. things like Nullable, MaxLength, Precision etc.
And we needed a class hierarchy because different types of properties have different sets of available facets.
The...
0
kicks
A Handy Extension Method: Raise Events Safely
Raising events is a very common practice. We do that a lot and it’s pretty irritating to check for nullity every time. The simple extension methods I present in this post spare the need to repeat this practice every single time.
0
kicks
How and when (not) to use Extension Methods in C# and .NET?
Lets first briefly examine Extension Methods, show some basics usages and then we will tackle some more advanced and concrete examples used to provide fluent, natural DateTime operations (similar to Date and Time operations available in Ruby on Rails).
0
kicks
Add scripts to head dynamically
Many times when i develop a user control i have the need to add some javascript to the header of the page. But the header doesn't have a method where you can add script and RegisterStartupScript inserts the script at the bottom of the page.
So i thought let's create an extension method...
0
kicks
.NET Utility Libraries Galore
Yesterday Karl Seguin announced a new .NET Extension Library. One of the really interesting pieces of the library is a streamlined approach to a simple dictionary imagecache, which is similar to the one described in another interesting looking utility library called ShadeTree. Recently, Ayende Rahei...
0
kicks
Vb.Net one better than C#
This is the first time I have envied VB over C#. Here's a thing that is useful and you can do in Vb.Net, but not in C#.
0
kicks
C#: Enhance Enums using Extension Methods
Extension Methods are one of the coolest features that have been added in .NET 3.5. I've heard arguments that there is no reason to use them, and the only reason Microsoft added them is to enable the ability to buid LINQ. Well, I do not entirely agree with that statement; in fact, I have found a coo...
0
kicks
Extension Methods
It is one of the new feature introduced in C# 3.0 “As the name implies, extension methods extend existing .NET types with new methods.”
Here i am going to extend the String type to write an extension method.
Example Adding a IsValidEmailAddress method onto an instance of string class:
0
kicks
Finally, a Good Reason for an Extension Method
I finally understand why extension methods are useful.
0
kicks
Extension Methods + Attributes = A Whole New World!
A post about combining attributes and extension methods in order to extend current code.
0
kicks
Useful Extension Method On String
.NET Framework provides String.IsNullOrEmpty() method which return true if the string is null or empty. It does not however take care of a string which only contains spaces. Often while persisting data we do not want to persist just empty strings. In past I have made this check before I let my data ...
0
kicks
Extension Methods and Scoping
There are a few scoping rules that you must keep in mind when using extensions methods. Problems with scoping and extensions methods are rare, but when you encounter them they are quite vexing.
0
kicks
MVC: Creating SSL Links/URLs
A couple days ago a reader sent in a question regarding how to use SSL with the MVC framework. Specifically the reader wanted to know the easiest way to make an Ajax call to a HTTPS page from a non HTTPS page. The tricky part here is to do so without hard-coding any URLs, so I whipped up a few exten...
0
kicks
LINQ Single and SingleOrDefault
This post explains about the Single and SingleOrDefault extension methods of LINQ, possible exceptions which can be thrown, and provides code examples both in C# and VB.NET along with code comments.
0
kicks
Extension Methods Roundup: IndicesWhere, TakeEvery, Distinct
IndicesWhere: Gets the indices where the predicate is true.
TakeEvery: Take items from 'startAt' every at 'hopLength' items.
Distinct: Gets distinct items by a comparer delegate
and Gets distinct items by comparer and hasher delegates (faster than only comparer).