Posts

Showing posts with the label InformationBox

.NET 4.0 version of InformationBox

At long last, a .NET 4.0 version of InformationBox was published on CodePlex! As you might expect, it now supports the optional and named parameters making it a little easier to read the code. You can grab the latest source code release from here: http://infobox.codeplex.com/SourceControl/list/changesets

Methods taking variable number of args (part 2)

In my previous post , I talked about the choice I made about taking a variable number of parameters. At that time, I used a simple params object[] , and the logic was built into the method (in the constructor of the underlying form in fact, but it is not relevant here). The problem with this approach is how to handle parameters with the same type but different meanings. A very simple example is the caption and the text of the InformationBox. Both are strings but how to differenciate between the two. I had to force the first parameter to be the text, but it was beginning to look like the MessageBox. For those who are familiar with C# 3.0, you may have already guessed what I could have used if .NET 3.5 had been available at that time. I could have used object initializers. It is a simple constructor syntax that allow the developer to specify only the properties he (or she) wants to define. For example, assuming the Client class is already defined with two properties "Name" and ...

Methods taking variable number of args (part 1)

A few months ago, I started a small project on Codeplex , its goal was simple : providing an alternative to the default Windows Forms MessageBox. One of the things that annoyed me with the MessageBox was to be forced to provide values for parameters I did not want to change. Here is a little example : MessageBox.Show("Text", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information); Clearly in this case, I should not have to specify the third parameter since it is already the default value. So basically, I needed to create a method ( Show in this case) that take a variable number of parameters. The problem was with the types of the parameters, I have a whole lot of different types. At that time, I had two ways to achieve that : Providing an overload of Show for each combination of parameters. Using params and the only type shared by all the parameters : object. The first one is nice when you have two parameters, but in InformationBox we are now dealing with up t...