Geeks With Blogs
Eron Wright - All Killer No Filler blog

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!

Posted on Sunday, February 29, 2004 5:24 AM Technology | Back to top


Comments on this post: Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE

# re: Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE
Requesting 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.

Left by PrecisionSoft.com.ar on Apr 13, 2005 3:02 PM

# re: Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE
Requesting Gravatar...
The link seems to be dead on GotDotNet.

Any chance of posting your tool again?

Thank you -
Left by DotNetGuy on Feb 18, 2006 9:37 AM

# re: Code Generation for .NET - Enhance the output of XSD.EXE and WSDL.EXE
Requesting Gravatar...
GotDotNet no longer exists. I too would enjoy seeing what you wrote if you can repost it please!
Left by MacBean on Mar 03, 2010 9:55 AM

Your comment:
 (will show your gravatar)
 


Copyright © Eron Wright | Powered by: GeeksWithBlogs.net | Join free