Make your own code candy in C#.

Pseudo candy

public void DoSomething(action myAction)
{
try{
myAction.invoke();
}
catch {
//Do some special handling
}
}

Usage

var _a = “a;”
DoSomething(new {o} ->{
//Do something to invoke.
Console.Writeline(_a);
});

Summary

As you can see, we can use the action delegate to create a method wrapper to do something complex and hide its inner working.

However, this doesn’t make trouble shooting any easier. Nor does it make your code magicly better. You still need to make sure your code is as bullet proof as possible.

Without the code candy-ish-ness.

private someThing(string A)
{
//<==Move error handling here.
//Do something to invoke.
Console.Writeline(A);
}

var _a = “a;”
someThing();

Benefit

Your funtions are now more specific to what you need. There is less room for code abuse.

Closing statement

Though I don’t look down on using the pseudo code candy, I strongly suggest that if you use it in a team environment, you don’t abuse it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.