Code Snippets from Work and Play Volume I

///Code Snippets from Work and Play Volume I

I have my career and I have my hobby, which blissfully happen to be the same. I do different software design for work than for play (typically). I like to share, so while you won’t see the heavy, important IP from work anywhere in this blog, I will share code where I see fit, so here is Code Snippets from Work and Play Volume I, which includes code from work and play intermixed to because it comes to me when it comes to me.

Enjoy!

Tired of all Those Try/Catch Blocks in your Code?

Particularly in a WinForm’s app interacting with primarily the base class libraries and maybe one or two other 3rd party APIs, you end up wrapping your code in a try/catch block that accounts for the most likely types of exceptions thrown, backstopped by catching the general case. I have used snippet manager and snippets for this for a long while until it struck me that an extension method is perfect for this:

You may have methods that take parameters, etc, and you can do what you need to do to extend or overload this to make that work, but in the app I am working has both a menu and tool bar item for every action, so I wrap the core of the action into a Perform method: PerformLoad, PerformLogin, and so far forth. So this works great, plus it then becomes an expression body with a Try/Catch blog :-)

Here is a Simple One – String to Stream

So you want a string turned into a stream?  We do it all the time. Here you go:

Use it like this: The astute may ask “what about disposing of the underlying stream?” Looking at the implement in dotPeak, you can see .Close() is called on the inner stream, which in turn calls .Dispose() so don’t fret:

Using NextPageToken with Blogger API .NET

Registry Extensions

These extensions allow you to do things like the following: Now that I think about it, the reason I put most of these extensions together was for a project called Registry Analyst, that gave you a better graphical UI into the Registry and also a command line tool for exporting registry data for search purposes. Searching text is much faster than searching through the registry via Win32 and many things don’t change plus you could easily do a diff between snapshots to see what changed–maybe between instances of running a particular program or even comparing the registry from one machine to the next. It is a lot more readable and faster than using RegEdit to do the export. Anyway, maybe I will get that project put together and posted.[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]
By | 2017-11-17T11:30:35+00:00 April 27th, 2017|Categories: .NET, Development|Tags: , , |1 Comment

About the Author:

Thanks for taking the time to read my profile and presumably my posts. I am a big city person living in a tiny town that offers no distracts from my passion: Creating software that helps others be more productive, happy, and enhances their work or personal life. I am a life-long learner, builder, writer, tinkerer, and when duty calls, an focused engineer and project manager.

One Comment

  1. […] Previous […]

Comments are closed.