Archive for the '.NET' Category

Creating ASP.NET HttpCookie-compatible multi-valued cookies in JavaScript

Cookies are ubiquitous on the web. They’re used to store usernames, login tokens, shopping cart contents, and so on. In libraries, cookies are typically modeled as name-value pairs. An API consumer requests a cookie using a known name (e.g. $.cookie('user') in jQuery with the Cookie plugin) and the library returns a string (e.g. alice). Sometimes, however, just plain old name-value pairs aren’t enough. In this article, we will take a look at how to bake multi-valued cookies in JavaScript that are compatible with the Values property of ASP.NET’s HttpCookie class.

Read more »

Things I miss from Java while programming in C#

One of the perks of being a freelance programmer is that I get to program in a lot of different languages, either because the client has dictated a certain language, has left the choice up to me, or limited me by what is supported by a host (Hi PHP!).

As fate would have it, I have had the good fortune to have extensive experience with both C# and Java. While many articles will list things a programmer misses from C# while coding in Java (properties, LINQ, reified generics, type inference, named and optional parameters, closures, continuations), this post intends to look at things a Java programmer might miss while coding in C#.

Read more »

Inconsistencies in the .NET Enum class

During a recent project of mine, I had to do a lot of enum manipulation using the .NET Enum class and I have to say I wasn’t impressed. Besides the shortcoming of it not being a generic class (and thus not being especially type-safe), Enum also has some strange inconsistencies in terms of how it handles matched integral types.

Read more »

Why your custom EnumStringType might not be working

I recently spent a couple hours yesterday to fix a problem I was having with my custom EnumStringType (see this post).

Basically, what was happening was when my repository was making a call to ICriteria.List(), which in turn called the Set method of EnumStringType, it was always passing in a lowercase string instead of an enum instance.

Read more »

How to put spaces in your NHibernate enums

NHibernate lets you map C# enums to database columns. This can be quite convenient in cases where you have a database column for something like gender. To map them, you follow the procedure outlined here.

That works all fine and dandy, as long as the strings you want to store in the database are valid C# identifiers.

Read more »

Joshua Bloch’s Builder Pattern in C#

Having spent a lot of time programming in Java over the last two years, I’ve made heavy use of Joshua Bloch‘s Java Builder pattern (also Effective Java Item 2).

Recently, I’ve started a fairly large project in C# 3.0. As it happens, there came a point where I wanted to use a pattern similar to Bloch’s Builder. However, as anyone who tries to use this pattern in C# will quickly find out, Bloch’s Builder doesn’t translate perfectly to C#.

Read more »

Convert PHP date format string to .NET DateTime format string

I recently had to convert some JavaScript code I’d written that used a PHP-style date format string to a .NET DateTime-style date format string.

It would’ve been a helluva lot faster to have had some sort of conversation table. After a little searching on Google, I found nothing so I decided to make one myself. Behold, the fruits of my labour!

Read more »

Exploring Java and VB.Net Syntax, Part 1

The syntax of a programming language is a large part of how a programmer interacts with a language. Being somewhat of a programming language enthusiast, I’m always curious about how different programming languages stack up syntactically.

Today, I’m going to take a look at an variety of programming tasks and show how they are done in both Java and VB.NET (the .NET 1.1 version). Since both these languages have differing feature sets, I’ll try to only use features that both the languages have, in order to compare them fairly. I know this might misrepresent the complexity of the languages, and I’m cool with that. The purpose of this post is merely to explore and discuss the syntax of each language.

Read more »

Creating an HTML document with .NET

Sometimes when you’re programming, you’ll want to generate an HTML document. This may be because you’re writing some sort of web app, or maybe you want your program to be able to output in a web-friendly format.

Read more »