DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

15
kicks
published 4 months, 15 days ago, submitted by crpietschmann crpietschmann 4 months, 17 days ago

pietschsoft.com — 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.

Add a comment 3 comments | category: | Views: 431 | Get KickIt image code
tags: , , , , | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:
I think I'd prefer this, it's far more reusable:

public static A GetAttribute<A>(this Enum @enum)
where A : Attribute
{
if (!@enum.GetType().IsEnum)
return null;
object[] attributes = @enum.GetType().GetField(@enum.ToString()).GetCustomAttributes(typeof(A), false);
return attributes.Length > 0 ? (A)attributes[0] : null;
}
posted by fquednau fquednau 4 months, 15 days ago
Oh, we still do smilies in code? *sigh*
posted by fquednau fquednau 4 months, 15 days ago
All this extension method stuff scares me. It is kind of like inventing your own language for a program. Not sure if that is a good idea. Interesting though
posted by samdnp 4 months, 15 days ago



information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge