Generics Best Practice

This is the Microsoft listed best practice for generics.

I agree with the following post. Here Richard Birkby recommends subclassing generics before using them.

His argument is that this make it easier to extend (which is a good idea) but I would also recommend subclassing to reduce the repetitive nature of the code:

For example:

public class foo

{

public List<int> Bar

{

get {return _Bar;}

}

private List<int> _Bar;

}

 

Would be more cleanly written as:

public class IntList : List<int> {}

public class foo

{

public IntList Bar

{

get {return _Bar;}

}

private IntList _Bar;

}

 

 

 

 

Late Binding in C#

The following is an example of late binding: 

            Type objClassType;
            object objApp_Late;
            objClassType = Type.GetTypeFromProgID(“VisualStudio.DTE.8.0”);
            objApp_Late = Activator.CreateInstance(objClassType);

Exploring Visual Studio 2005

Visual Studio is a combine harvester of an IDE. It performs so mant functions that it is easy to get lost. 

I started sting to write an extension to VS.NET to allow me to use the command-line from within VS. I was trying to use the VSIP to add a managed window.  Partway through the listed steps it asked me to look at the View | Other Windows menu. I could not find the window that I had defined but  I did  find  the follwing:

  • Call Browser
  • Command Window
  • Object Test Bench 

 The call browser could be worth future investigation.

Object Test Bench allows objects to be created from the IDE.  This could be great for ad-hoc testing. (Although I typically used the TestDriven.NET which allows the test this method or test with debugger).

The Command Window looks much more useful. It contains a wonderful set of commands and is user-extensible. I can see this becoming really useful.

 Here is the list of available commands.

Technology Convergence

It is a good sign when different teams are attempting to solve the same problem.

The Castle Project has its new Generator contrib project. This is an easy to use extensible code template system written in BOO with asp.net style templates. BOO is a hybrid of Python and C# with some ideas from the Ruby world.

Microsoft has the Guidance Toolkit. This allows the Visual Studio IDE to expanded with macros and recepies.

Both of these approaches are attempts to implement Software Factories, allowing developers to raise the abstraction and reuse. This can only be a good thing. Hopefully one or both will survive.

Code Generation of Stored Procedures with examples

This is an article on code generation of stored procedures with examples.

 

Here is the main outline of the stored procedure generation template

<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;
<xsl:output method=”text” standalone=”yes”>
<xsl:preserve-space elements=”row”>
<xsl:template match=”/”>

</xsl:template>

</xsl:preserve-space>

</xsl:output>

!— BODY

This is how to construct the insert body.

INSERT INTO <xsl:value-of select=”$name”> (<xsl:for-each select=”columns/row”>
<xsl:value-of select=”@COLUMN_NAME”>
<xsl:if test=”position() != last()”>, </xsl:if>
</xsl:value-of>)
VALUES (<xsl:for-each select=”columns/row”>@<xsl:value-of select=”@COLUMN_NAME”>
<xsl:if test=”position() != last()”>, </xsl:if>
</xsl:value-of>)
</xsl:for-each></xsl:for-each></xsl:value-of>

 

With this as a stub it will be easy to create the script. 

COM ProgIds in C#

This article describes how to add ProgIds to a C# App an expose it as a COM dll.

The key feture was this line.
[GuidAttribute("1F2A0E29-1934-4E2F-8E25-89467D68F3A9"), ProgId("Leszynski.InSpireAddin")]

 The article also includes registration details.