Blog Stats
  • Posts - 24
  • Articles - 0
  • Comments - 61
  • Trackbacks - 92

 

Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE

Have you wondered how the XSD tool and the WSDL tool in the .NET Framework can target numerous managed languages?  Internally, it uses a great technology called CodeDOM. CodeDOM is a set of classes in the .NET Framework that facilitate code generation. Here is a sample of CodeDOM in action, generating an Order class.

using System;
using System.CodeDom;
using System.Reflection;
public class CodeGenerator {
      public void GenerateOrderType() {
            // declare an "Order" type
            CodeTypeDeclaration decl = new CodeTypeDeclaration("Order");
            // implement ICloneable
            decl.BaseTypes.Add(typeof(ICloneable));
            // add a field
            decl.Members.Add(new CodeMemberField(typeof(int), "OrderID"));
            ...
      }
}                                                                                  

The XSD tool builds up a CodeDOM compile unit describing the classes to be generated, then instantiates a CodeDOM provider to generate source code in a specific language. Providers exist for many .NET Framework languages. The tool supports a command-line switch to specify the desired CodeDOM provider.

By writing a custom CodeDOM provider, we can augment the generated classes with great features - replace fields with properties, replace arrays with strong collections, implement IClonable, generate IComparer instances, and more! 

At Point2 I wrote an extensive library to do just that.  We recently shared-sourced it here: http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=80258a8c-bb4c-48e6-948b-05f6da568f55

Enjoy!


Feedback

# re: Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE

Gravatar Really GOOD!
It would be nice if you can implement IBindingList for Collections so that you can directly bind to datagrids and for example AllowSorting.

4/13/2005 3:02 PM | PrecisionSoft.com.ar

# re: Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE

Gravatar The link seems to be dead on GotDotNet.

Any chance of posting your tool again?

Thank you - 2/18/2006 9:37 AM | DotNetGuy

# re: Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE

Gravatar You can use AppDomain.CurrentDomain.BaseDirectory to accomplish the same things in all .NET apps. 10/19/2009 10:15 PM | tiffany key ring

Post a comment





 

 

 

Copyright © Eron Wright