C#

Data Structure and Algorithms eBook

After dark years, seems like good things are coming out from the Italian .NET community lately: the latest one is the free eBook on Data Structures and Algorithms wrote by Granville Barnett and the Italian UGIdotNET member, Luca Del Tongo. I remember studying such things at the university, and the last time I helped a friend with his studies the books were still the same, and still based on "old" languages like C. Finally now a book covers the same important topics but with samples written in a modern object oriented language. All the algorithms of the book are available in form...

String to Enum

This might seems a pretty trivial problem, but every time I've to get an Enum given its name I forgot how to do it, and I've to look for it on Google. So, is there a better way to remember something you always forget than writing a post about it? Back to the problem: going from an Enum to its numeric value or its string representation is quite easy: /* Enum to string */ string stringValue = enumVal.ToString(); /* Enum to numeric value */ int numericVal = (int) enumVal; And going from a numeric value to the Enum is quite as easy: /* Numeric value...

How to add a required validator to a CheckBoxList

If you add a normal RequiredFieldValidator and you want to validate a CheckBoxList, you will get a runtime exception informing you that the CheckBoxList cannot be validated. Sometimes you want to make sure the that user has selected at least one of the checkbox in the checkbox list, but as aforementioned, if you user a normal RequiredFieldValidator you will get an exception. You could use a CustomValidator control, but a nicer and more reusable approach is to build a custom web control that extends the BaseValidator. I found a 2001 article on how to do that (Building a CheckBoxList Validator Control) but...

SetData to clipboard failing on VirtualPC

After a nice 4 days trek on the Marlborough Sounds (pictures and short report to come soon), I'm back at work. We are close to the release of the next version of our main product, so we are setting up some VirtualPCs to test it. And we found a problem on a portion of application that never caused problems: a simple Clipboard.SetDataObject. Looking at the documentation on MSDN I found that NET 2.0 added a new overload to the SetDataObject method: public static void SetDataObject ( Object data, bool copy, int...

Going dinner with NET 3.0

The Microsoft Platform Evangelism team released a very nice technology demo product to show all the new cool technologies Microsoft just released or is going to release during that year. The demo utilizes several technologies including: IIS7, ASP.NET Ajax Extensions, Linq, Windows Communication Foundation, Windows Workflow Foundation, Windows Presentation Foundation, Windows Powershell, and the .NET Compact Framework. They are developing the demo on CodePlex, so you can download the code directly from there. The also build a web site DinnerNow.net, that will contain a working demo, and will host videos showing the features of the "product". At the moment...

Fine tune your properties with accessors

How many times did you need a property to be read-only for the users of your API, but also you needed that property to be populated by your own data access layer? It happened to me many times, and I usually solved that problem accessing directly the underlying field changing its visibility from private to internal or protected. But what if you want to access everything as a property and don't want to hook directly to the field?You need to be able to specify for the setter a different visibility for the getter. Here is how: ...

NHibernate in 8 minutes

Yesterday afternoon I delivered my first speech in English: NHibernate in 8 minutes during the Lightining session at the Wellington .NET user group meeting. I hope my English was not too bad, and that I managed in making a brief overview of the power of NHibernate. If you attended my presentation, please write a comment about it, and also if you would like to listen to a more detailed presentation of NHibernate. For the moment you can download the slides and the demo of the Lightning presentation.

Your encryption algorithm may fail moving to .NET 2.0

In my first week of work in Wellington at Calcium, I'm starting to migrate the application from .NET 1.1 to .NET 2.0. The wizard did correctly almost all of the job, and the only thing I needed to change to make it compile without too many warnings was changing the old (and obsolete) Parameters.Add with the new Parameters.AddWithValue (I think I did it 1000 times). Once it compiled we had a very strange problem: we are sending username and password, encrypting them using TripleDES, then serializing as string and then sending over the wire with remoting. And of course decrypting them...