Helpful Code Snippets


TryConvertTo<T> C# Helper
This snippet of code has been in my arsenol for many years. I am not sure where I first learned it or heard of it, but it finds its way into nearly all of my projects. Using Generic types it allows for quick and accurate conversions from any data-type to any other data-type. If the conversion cannot happen the default of the targeted data-type is returned.

See the Code

Expression<Func<T, bool>>
When working with an ORM like Entity-Framework this can be incredibly useful for building dynamic queries from an entity in a function. It allows you to pass a function as a parameter and have that function be executed on the entity. I need to credit a fellow student who I had the priviledge of working with at Penn State on my Capstone project for this one.

See the Code