logo

.NET DST Calculator

I have a common .NET library written in C# that I use everywhere. I call it mattmc3.Util, and it contains helper methods (static classes or extension methods) that correspond to Microsoft’s BCL. So, for example, I have a DateTimeHelper with static methods that corresponds to the System.DateTime class. The DateTime class is one of the most anemic in the .NET library, mainly because MS has to deal with international customers, so methods like DateTime GetMemorialDay(int year) are too regional and clutter the BCL, but are essential in the American business world.
3 minutes to read

C# Corner - fun with yield and extension methods

All .NET developers learn about IEnumerable and IEnumerator in their first day of development, whether they realize it or not. Every foreach statement written utilizes the .GetEnumerator() call to iterate over a collection of objects. The “For Each” concept is a really nice piece of syntactic sugar. However, one of its limitations is that it doesn’t give you a counter to track which loop iteration you’re on. If you want to do that, you have to keep track of it yourself in your own variable.
4 minutes to read

Bad cache

We had some code break down today. Here’s the story. One of the great tricks in the object oriented world is late bound variables. When it’s expensive to initialize a variable, or you’re not sure you’re going to always use it, you don’t initialize it until first use. Public Readonly Property Something() As SomeObject Get If _someObject Is Nothing Then _someObject = DoExpensiveInitialization() End If Return _someObject End Get End Property Private _someObject As SomeObject Another great trick is caching data.
3 minutes to read

Preconditions

Google’s been doing some interesting things lately. Some attract lots of attention, some very little. One that you may not have heard of is Google Collections . It’s just a series of Java helper classes. At first it may seem like a non-event, and mostly for us .NET folks that’s true. But I read this post about a year ago, and my interest was piqued by their Preconditions class. It’s nothing significant - it just throws various argument exceptions if you don’t pass “true” to its methods.
2 minutes to read

Embedded Resources

In the .NET world, ORMs are only just now beginning to see the light of day. Though nHibernate has been around for awhile, it has not seen much uptake from mainstream .NET devs. It may have to do with typical FUD stuff, like its roots in the Java world, its reliance on XML for the mappings, its learning curve, or the lack of books and beginner’s resources. I’m not judging - I’ve read this book and I think nHibernate’s offerings are the most mature and robust available for .
4 minutes to read