Event Extension Methods

by Khalid Abuhakmeh 6. January 2009 10:41

I'm sure I'm not the first to write these extension methods, and if I am I would be amazed. Here is a small static class to make the invoking of events more readable. When you invoke an event, the code might look like the following.

if (OnCreation != null)
OnCreation.Invoke(sender,e);

I reduced it to an extenstion method that looks something like this.

// No sender or event arguments
OnCreation.IsNotNullThenInvoke();
// Only with sender
OnCreation.IsNotNullThenInvoke(this);
// With sender and event arguments
OnCreation.IsNotNullThenInvoke(this, e);

And here is the code.

public static class EventExtensionMethods
{
public static void IsNotNullThenInvoke(this EventHandler target)
{
target.IsNotNullThenInvoke(null,EventArgs.Empty);
}
public static void IsNotNullThenInvoke(this EventHandler target, object sender)
{
target.IsNotNullThenInvoke(sender,EventArgs.Empty);
}
public static void IsNotNullThenInvoke(this EventHandler target, 
object sender, EventArgs e)
{
if (target != null)
target.Invoke(sender,e);
}
}

There you have it, a single method that extends events. Less code, makes your code easier to read. Hope this helps.

Note: There is no validation on the arguments being passed to the extension methods, this means you could pass in null arguments. In terms of events, I feel this is ok.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Code | Code Review | General

Merry Christmas, Hanukkah, Kwanza, and Holidays in General

by Khalid Abuhakmeh 24. December 2008 18:00
Well tomorrow is Christmas and I'm excited about the upcoming new year. I have some goals to achieve next year and will hit the ground running as soon as the clock hits 12:00:01 on January 1st. I can't believe it's been five months since I started this blog. I didn't know what it would do for me or how it would help. The reality is, that this blog has made me a better developer and critical thinker. It also makes me appreciate the better parts of development. There have been times where I questioned my love of programming, but the online community always reminds me that there are people just as passionate as me. I am also grateful to the people who actually read my ramblings (even if you don't agree). Thank you reader and friends and have a Happy Holiday.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General | Rants

My BFF - Regular Expression Quick Replace

by Khalid Abuhakmeh 24. December 2008 11:27

Killer NerdRecently I fell into some VB6 code that I had to convert over to C#. At this point, I am convinced that VB stands for Very Bad. Oh the humanity, I have never had to develop anything that was so draining, and I've programmed compilers in the past. It is amazing to see the leaps and bounds in C# .NET as compared to VB6; it is a paradigm shift I'm glad happened. This code just wasn't VB6 code, it was terrible code.

This code was the kind of code that makes you curse the original developer. Why would somebody make a method 3000 lines long? It was like looking into an abyss of never ending if statements. A fellow programmer printed an image of a handgun and slid it on my desk as he said "here's an out." Luckily VS2008 can read VB6 projects, and I was able to convert from VB6 to VB.NET, followed by a VB.NET to C# conversion. It wasn't perfect, but it was a good start. That's when the real fun started.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Code | General | Rants | Warnings

Supercharged Browsing

by Khalid Abuhakmeh 24. December 2008 09:08

Grandpa Munster - Creator of the DragulaEver since I started using Firefox, I've fallen in love with extensions. Firefox is the perfect browser for developers because it gives you so much in terms of productivity extensions. You have your standard extensions like Web Developer and FireBug, but there is a clear winner in my opinion; the one extension I use more than any other is Easy DragToGo. Easy DragToGo lets you drag links, images, or even text and open it up in another tab in Firefox. I love using it on social news sites like Digg and DotNetKicks because it lets me pick out the articles I want to read at one time. Once I have selected the stories I want to read, I can close them down one by one after I'm done reading. It is also helpful when someone puts a link on a page that isn't hyperlinked. You can highlight the web address and drag. The extension is smart enough to know it is an address and go there. You can also drag words and the extension will do a google search on it. A note of caution though, it takes some getting used to, so give yourself a little while to adjust. Go supercharge your surfing power with this extension; once you do, the Internet will never be the same.

Grandpa Munster's Dragula
Get it? Easy DragToGo.... Dragula....?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

General | Products

Oxite Sorta Smells

by Khalid Abuhakmeh 14. December 2008 20:28

Attack of the Killer TomatoesSo Microsoft just released a sample MVC project for all developers to aid in groking ASP.NET MVC. At the same time I am in the efforts of helping my younger brother start a new business, and I am looking for a platform that he can use to create some sort of web presence. So I was really excited to see that Microsoft just released something for developers to sink their teeth into. Oxite is a new blog engine/content management system built on top of ASP.NET MVC. The fact that is is ASP.NET MVC is a definite plus because this lets me consult the services of actual designers. I can put down the pen tool in Photoshop, for now. The designers can be tasked with creating beautiful HTML designs, while I focus on extending Oxite for the needs of my younger brother. Upon further inspection of the product, it seems like an OK start to a project, but some things smell; from a developer's viewpoint and a user viewpoint. I'll first explain the concerning parts from a developer viewpoint, followed by the user viewpoint.

Note : I realize this is alpha, so I am still very excited to see what comes next, but I wouldn't use it as it is right now.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Code Review | General

SubSonic 3 REST when I'm dead - T4 template

by Khalid Abuhakmeh 12. December 2008 21:35

Rest StopSubSonic 3 recently went Alpha and I couldn't wait to jump on it and extend it. Rob Conery has done a great job and the use of T4 templates just makes the possibilities limitless. I've also wanted to explore REST more with some rubber meets the road development. I have a good grasp of what REST (representational state transfer) is, but I haven't had the oppurtunity to use it since I am heavily entrenched on business applications. Business applications usually stress security, and with REST you don't really get as much as you would be a protocol like SOAP. I'm not going to argue which one of these implementations is better. I will show you how I was able to take SubSonic 3 Alpha, WCF 3.5, and T4 templating and create a REST web service. What you will see in this post is the T4 template and the final result. I have also included the project if you just want to download and play around. This is early and can probably be improved a lot, but I think it is very promising.

Note: You will need Northwind to run this particular example without modification.

SubSonicRestWcf.zip (1.03 mb)

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , ,

Code | General

Doppelgänger Datacontract - WCF Gotcha

by Khalid Abuhakmeh 18. November 2008 20:59

As a developer I am never suprised that the seemingly simple tasks always end up being the ones that get you; and it wasn't a suprise that WCF would have one of those small gotchas that drain your productivity and patience. Wikipedia defines a doppleganger as the following : ""Doppelgänger" has come to refer (as in German) to any double or look-alike of a person. The word is also used to describe the sensation of having glimpsed oneself in peripheral vision, in a position where there is no chance that it could have been a reflection. They are generally regarded as harbingers of bad luck. In some traditions, a doppelgänger seen by a person's friends or relatives portends illness or danger, while seeing one's own doppelgänger is an omen of death." Scary right? Well it gets worse. It seems that the Doppelgänger has found it's way into your WCF datacontracts to haunt you with obscure errors and difficult debugging. Don't worry it is quite easy to get rid of your Doppelgänger problems. So let me start by first defining the problem.

WCFExample.zip (29.17 kb)

More...

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Code | General | Warnings

The Architect's Way - NDepend

by Khalid Abuhakmeh 16. November 2008 17:20

Dominion-Prequeal to the ExorcistSo remember that article I wrote about the death of Software Engineering, yeah that one. Well it seems that one company is trying to resurrect the art of engineering, helping it off it's death bed and into an olympic sprint all in one fell swoop. That tool is NDepend, a tool designed to give you better insight into pre-existing code bases. With NDepend you can do things like comparisons of builds, better understand code structure, impact analysis, capture architectural constraints, and much more. I also happen to love the Code Query Language feature. It lets you write SQL-esque queries to examine your development. I really suggest you check NDepend out. I'm going to explain why you need a tool like NDepend at your company, development shop, or even in open source projects.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

General | Products | Warnings

QueryString Candy - Could Rot Your Teeth

by Khalid Abuhakmeh 12. November 2008 21:24

The Dentist 2 - Brace YourseflSo I was reading one of my friends blogs and noticed that he had a post about parsing the QueryString property in the Request object. He did a good job and you should read that post; but in the spirit of development, I felt that it could still be done a little better. I love generics and think they should be used whenever possible, it leads to a more concise and clearer API. So I sat down and started coding, but soon found myself scratching my head, how do I create a generic method that has constraints of value types: int, decimal, float, string, and Guid. You can constrain generic methods but only with interfaces and classes. I almost felt like I was barking up the wrong tree, but the problem seemed like it could be done with generics. I wanted a clear API, was I wrong? Of course, not! How dare you suggest that I would be (haha, just kidding, I'm wrong plenty of the time). So as Rob Conery (whose code helped me solve this problem) would say, "Let's See The Code Already!"

QueryStringExample.zip (204.56 kb)

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Code | Code Review | General

Development Lexicon - Compost Development

by Khalid Abuhakmeh 10. November 2008 21:38

Toxic AvengerCompost Development :

Dicitionary.com defines compost as the following: 

A mixture of decaying organic matter, as from leaves and manure, used to improve soil structure and provide nutrients.

Compost Development doesn't have any of the positive aspects associated with real composting. Compost Development is the idea that developers write crappy code on top of other crappy; usually due to the fear of breaking the initial crappy code or the lack of time or resources to fix the underlying code. Overtime you are left with multiple layers of crappy code, that is unmanagable and inefficient. Usually everybody makes excuses as to why the code is the way it is, but everybody knows deep down that there is a problem.

 

Use :

Khalid : "Why don't we rewrite this section of the code?"

Andrew : "I'd love to rewrite this section, but it is so critical now and is used in so many parts of the code that it would take too much time. It's Compost Development man!"

Khalid : "Haha, yeah that sucks." 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

General | Lexicon

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

A Little Narcissism

I am a .NET developer mainly focused on Web development and enterprise applications. I strive to keep my skills at their best and always looking to absorb that much more knowledge. I am learning new things like Windows Workflow Foundation, LINQ, Ruby on Rails, WPF, ASP.NET MVC, and anything else thrown at me; I say bring it on!

RecentComments

Comment RSS