Welcome to MSDN Blogs Sign in | Join | Help

CodeDom now supports a way to generate code for CodeTypeMember [Vinaya Bhushana Gattam Reddy]

CodeDom now supports a way to generate code for CodeTypeMember.

In V1.1 there is no way to generate a method without a type information using CodeDom. There are several tools and applications including ASP.Net had requirements to create a method without the type or namespace information. Currently one has to parse the generated code or file to get the method code but that work around is horrible because it’s hard to implement and one has to come up with a solution that works for all the languages.

In Whidbey, we added an API to the CodeDomProvider class to generate a method or in general any CodeTypeMember type code directly without the type information. We have re-arranged the existing code generation API’s little bit to support this new feature and to provide consistency across all code generation API’s. We did the following changes in Whidbey to support this functionality…

  1. Obsoleted ICodeGenerator and ICodeCompiler interfaces.
  2. Moved all the methods in those interfaces to the abstract class (CodeDomProvider)
  3. Added GenerateCodeFromMember( CodeTypeMemeber, …)

Providers support:

Not all Microsoft Code Providers supports this new API in Whidbey time frame. The workaround is that one would be able try the call and catch exceptions to determine if it's supported or not. It’s kind of ugly but we have plans to provide a better mechanism in the next release to query the Code Provider to see whether it supports code generation from CodeTypeMember or not,

Code Snippet: The following code snippet demonstrates how to generate code for method without type information.

            CodeMemberMethod method = new CodeMemberMethod();

method.Name = "TestMethod";                       

CodeDomProvider provider = new CSharpCodeProvider();

StringWriter writer = new StringWriter();

provider.GenerateCodeFromMember(method, writer, null);

Console.WriteLine(writer.ToString());

writer.Close();

Sample output:

private void TestMethod() {}

Published Tuesday, March 15, 2005 9:47 PM by BCLTeam
Filed under:

Comments

Tuesday, March 15, 2005 11:49 PM by どっとねっとふぁん blog

# CodeDom now supports a way to generate code for CodeTypeMember

CodeDom now supports a way to generate code for CodeTypeMember
Wednesday, March 16, 2005 9:28 AM by eden li

# re: CodeDom now supports a way to generate code for CodeTypeMember [Vinaya Bhushana Gattam Reddy]

Yay! Finally :)
Thursday, March 17, 2005 3:16 PM by David Boschmans' Weblog

# Tips

Tips
Monday, March 21, 2005 12:36 PM by Ido Samuelson

# Tips

Tips
Thursday, July 21, 2005 8:37 PM by Sydney .NET User Group

# ApplicationCompatibility with .NET Framework 2.0

Thursday, July 21, 2005 8:40 PM by Sydney .NET User Group

# 3rd August 2005 - Application Compatibility with .NET Framework 2.0

Thursday, July 21, 2005 8:43 PM by Sydney .NET User Group

# 3rd August 2005 - Application Compatibility with .NET Framework 2.0

Thursday, July 21, 2005 9:17 PM by Sydney .NET User Group

# 3rd August 2005 - Application Compatibility with .NET Framework 2.0

Thursday, July 21, 2005 9:18 PM by Sydney .NET User Group

# asefa

Thursday, July 21, 2005 9:20 PM by Sydney .NET User Group

# 3rd August 2005 - Application Compatibility with .NET Framework 2.0

New Comments to this post are disabled
 
Page view tracker