tools

August 12, 2005 tools

Very Cool Nullable Fix

.NET 2.0 has the idea of a nullable” type built right in, e.g.

Nullable<int> x = null; // legal

This adds nullability to value types as well as reference types. Further, C# adds direct support with this syntax:

int? x = null; // legal

However, while the C# language was updated to support nullability, the CLR was not, which lead to problems with boxing:

int? x = null;
object y = x;
// a boxed Nullable<T> was never null
if( y != null ) Console.WriteLine(“Doh!“);

This problem was fixed this late in the .NET 2.0 game by getting a bunch of folks together to rejigger things so that the following works the way you expect:

int? x = null;
object y = x;
// a boxed Nullable<T> can now be null
if( y == null ) Console.WriteLine(“Wahoo!“);

Somasgar has the full scoop.

August 11, 2005 tools

What should I do w/ the metadata?

Imagine I’ve got some metadata” that describes some functionality of my system, e.g. the command line parameters to a tool:

<args description=“Two wrongs don’t make a right, but three lefts do”>
  <arg name=“lefts” description=“Number of left turns” type=“int” default=4″ />
  <arg name=“attitude” description=“Driver attitude” required=“true” type=“string” />
</args>

Once I have this metadata” in place, should I a) use it to generate a class at compile-time that implements the command line parsing, or should I b) use it to drive a command-line parsing framework at run-time?

If I do a), generate the code, the result might look like this:

class Args {
  public void Parse(string[] args) {…}
  public string Usage { get {…} }
  public int Lefts { get {…} set {…} }
  public string Attitude { get {…} set {…} }
}

I’ve got better perf, but I have to generate the code in some way and .NET doesn’t come with any built-in tools to do that (no, I don’t count ASP.NET or XSLT as good codegen tools). Plus, the command-line args are now baked in and require a re-compile to change and who cares about perf to parse the command line? Finally, I’m much more likely to have most of the work done in a base class, e.g.

class Args : ArgsBase {
  public void Parse(string[] args) { return base.Parse(args, …); }
  public string Usage { get {…} }
  public int Lefts { get {…} set {…} }
  public string Attitude { get {…} set {…} }
}

In my experience, most of the work of code-gen is generating the smallest possible bit of code to provide a nice wrapper around a base class that does most of the work in a very interpretive manner.

If I do b), have a run-time interpretter of the metadata,” I’ve got to build a command-line argument interpreter, but, as I’ve said, you almost always have that anyway. However, I also give up a develop-time wrapper aka Intellicrack” which will be pried from my cold, dead fingers.

What do you guys do?

August 3, 2005 tools

WinFX Beta 1 Online SDK Docs

July 22, 2005 tools

Cool Avalon Default Style Trick

Karsten shows a cool trick for pulling out the default style of an Avalon lookless control. This is super useful if you want to replace an existing control's look, but you don't want to have to start from scratch.
July 16, 2005 tools

My First MsBuild Task

Here. The one where I built my first custom msbuild task.
July 12, 2005 tools

Eric Sink: The Game is Afoot

I don’t know if Eric understands the ISV industry or not, but certainly seems to. Luckily, I’m on a real product team now, so I get to try to channel Eric into my work.

Eric’s latest writing is The Game is Afoot, in which he describes various games and then draws lessons from them for ISVs. It’s fabulous. He concludes by apologizing for the length and then teasing us with the analogies he left off. It wasn’t too long, Eric! I wanted more! (I also want your blog to have comments, but that’s another thing entirely…)

I think now I understand the public outcry when I suggested that I might cut down on the material in the Windows Forms 2.0 book

July 12, 2005 tools

Looking forward to the Portland Code Camp, 7/23-24

The session list for the Portland Code Camp, July 23-24, has just been posted. I’m especially looking forward to the following:

  • .NET Windows Forms Tips & Tricks
  • Forensic Development
  • Implementing Creature AI
  • Introduction to Inform
  • Introduction to Python
  • Introduction to Ruby
  • Ruby on Rails
  • MonoRail - ASP.NET on Rails
  • Web Unit Testing with Ruby and Watir

That’s only if my wife doesn’t have my working on the house (we’re prepping it for sale). Of course, I don’t know if she’ll understand that I’ve volunteered to give my own session: Some Cool Avalon Stuff

July 5, 2005 tools

Register for COM Interop and VS05b2

I was helping a colleague work through a .NET COM interop issue. He’d found my article on the topic (“Hosting Windows Forms Controls in COM Control Containers), but couldn’t get it to work. He’d set the Register for COM Interop setting and adding the Guid attribute to his .NET type, but nothing was registered at build-time.

The problem was that, unlike VS03, the wizard-generated AssemblyInfo.cs has the assembly-wide ComVisible attribute set to false” which causes regasm (the command-line version of what VS is doing to register your .NET assembly with COM at build-time) to skip the registration of all of the .NET types in your assembly, defeating the purpose of the Register for COM Interop option pretty thoroughly.

The trick, of course, is to set ComVisible to true”.