Bill Blogs in C#

Bill Wagner discusses C#, LINQ, and other items of interest

Creating Generic Methods
It's as simple as creating a static generic class

Martin Shoemaker wrote a recent post on his blog discussing a number of issues he had migrating TabletUML from .NET 1.x to 2.0, specifically discussing moving to generic collections.

I'll add a couple suggestions that hopefully makes your migration easier. 

First, Martin discusses a problem migrating this routine:

private void SelectMembers(
ArrayList members, ArrayList newSelection,
ArrayList selected, ArrayList unselected)

He choose to make the enclosing class (in his case, a Form) a generic class, and lamented that he could not create a generic method inside a non-generic class. I'd prefer moving that method out of the class and creating a new static class:

public static class SelectionUtilities < T >
{
  public static void SelectMembers(
    List<T> members,
    List
<T> newSelection,
    List<T> selected,
    List
<T> unselected)
  {
    // contents elided.
  }
}

I'm not certain it will work in Martin's case, because he did not include the full source to the original method. But, it sounds like no other member variables were affected, so this strategy works just fine.

Second, I want to clarify Martin's discussion of generics and SOAP serialization. Quite simply, it's a bug, not a practical limitation of SOAP.  You would not be able to serialize a generic class, but that's ok: you can't instantiate one either. However, you should be able to serialize a specific instance of a generic type.  By this I mean that you can't serialize List<T>, but List<string> should be no problem.

Microsoft has acknowledged this problem and has mentioned that the SOAP serializer will be deprecated with the Indigo, WCF XML Formatter.  See here for the details: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=147645&SiteID=1

Personally, I don't agree with the decision to drop support for the SOAP formatter before WCF is completed.



Published Monday, November 28, 2005 6:18 PM by wwagner
Filed under: ,

Comments

No Comments