Stories recently tagged with 'ExtensionMethods'

Another C# trick: Fluents, Inheritance and Extension Methods (blogs.msdn.com)

submitted by crpietschmanncrpietschmann(11.3k) 2 years, 3 months ago

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 base class of the hierarchy is called PropertyConfiguration which defines a series of Fluent methods that are shared by all sub types: read more...

add a comment |category: |Views: 26

tags: another

A Handy Extension Method: Raise Events Safely(blogs.microsoft.co.il)

submitted by shayfriedmanshayfriedman(1411) 2 years, 8 months ago

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. read more...

add a comment |category: |Views: 30

tags: another

How and when (not) to use Extension Methods in C# and .NET?(aspdotnetfaq.com)

submitted by spavkovspavkov(1708) 3 years, 3 months ago

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). read more...

1 comment |category: |Views: 456

tags: another

Add scripts to head dynamically(weblogs.asp.net)

submitted by djsoliddjsolid(429) 3 years, 6 months ago

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... read more...

1 comment |category: |Views: 25

tags: another

.NET Utility Libraries Galore(hsidev.wordpress.com)

submitted by crpietschmanncrpietschmann(11.3k) 3 years, 6 months ago

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 Rahein reviewed another .NET utility library called Umbrella, which looks like a pretty wide and deep set of utilities. As I am about to create a new solution to consolidate the utility functionality we use across our various projects, it got me thinking it might be time to pick an established (or growing) library from the community and try to contribute any missing pieces we need for our own projects. read more...

add a comment |category: |Views: 91

tags: another

Vb.Net one better than C#(blog.gadodia.net)

submitted by whoisvaibhavwhoisvaibhav(1000) 3 years, 6 months ago

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#. read more...

2 comments |category: |Views: 681

tags: another

C#: Enhance Enums using Extension Methods(pietschsoft.com)

submitted by crpietschmanncrpietschmann(11.3k) 3 years, 6 months ago

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 cool way to use Extension Methods to enhance the System.Enum object since it cannot be inherited. Even though Enum can not be inherited, it can be extended using Extension Methods. Here's the code to an Extension Method that extends the LocalizationMarket Enum with the ToDescriptionString() method that returns the DescriptionAttributes value for the given enum value. read more...

3 comments |category: |Views: 662

tags: another

C#: Enhance Enums using Extension Methods(pietschsoft.com)

submitted by crpietschmanncrpietschmann(11.3k) 3 years, 6 months ago

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 cool way to use Extension Methods to enhance the System.Enum object since it cannot be inherited. Even though Enum can not be inherited, it can be extended using Extension Methods. Here's the code to an Extension Method that extends the LocalizationMarket Enum with the ToDescriptionString() method that returns the DescriptionAttributes value for the given enum value. read more...

3 comments |category: |Views: 662

tags: another

Extension Methods(techbubbles.com)

submitted by kalyanms1kalyanms1(1720) 3 years, 6 months ago

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: read more...

add a comment |category: |Views: 16

tags: another

Finally, a Good Reason for an Extension Method(rauchy.net)

submitted by rauchyrauchy(455) 3 years, 7 months ago

I finally understand why extension methods are useful. read more...

add a comment |category: |Views: 37

tags: another

Extension Methods + Attributes = A Whole New World!(blogs.microsoft.co.il)

submitted by shayfriedmanshayfriedman(1411) 3 years, 7 months ago

A post about combining attributes and extension methods in order to extend current code. read more...

1 comment |category: |Views: 566

tags: another

Useful Extension Method On String(deepakkapoor.net)

submitted by deepakkapoordeepakkapoor(430) 3 years, 7 months ago

.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 pass through. Today I thought of creating an extension method to do the same for me. read more...

add a comment |category: |Views: 32

tags: another

Extension Methods and Scoping(blogs.msdn.com)

submitted by CharlieCalvertCharlieCalvert(7875) 3 years, 7 months ago

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. read more...

add a comment |category: |Views: 17

tags: another

MVC: Creating SSL Links/URLs(squaredroot.com)

submitted by TroyMGTroyMG(2670) 3 years, 7 months ago

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 extension methods that should make this a bit easier. read more...

add a comment |category: |Views: 275

tags: another

LINQ Single and SingleOrDefault(codeforeternity.com)

submitted by xtremebizxtremebiz(575) 3 years, 8 months ago

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. read more...

add a comment |category: |Views: 800

tags: another

Extension Methods Roundup: IndicesWhere, TakeEvery, Distinct(weblogs.asp.net)

submitted by JemmJemm(9604) 3 years, 8 months ago

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). read more...

add a comment |category: |Views: 25

tags: another