creating enumeration using .NET's CodeDom

Posted by Manish Sinha on Stack Overflow See other posts from Stack Overflow or by Manish Sinha
Published on 2010-04-17T07:10:35Z Indexed on 2010/04/17 7:13 UTC
Read the original article Hit count: 470

Filed under:
|
|

Hi,

I want to create an Enumeration using CodeDom API. I have searched enough on the internet and I get results which are hardly of any use.

What I want to generate is

public enum bug_tracker_type
{
    [Description("Bugzilla")]
    Bugzilla,
    [Description("Debbugs")]
    Debbugs,
    [Description("PHP Project Bugtracker")]
    PHP_Project_Bugtracker,
    [Description("Google Code")]
    Google_Code
}

I used CodeTypeDeclaration and set it's IsEnum property as true, created a name, and set it's Attributes.

Now the biggest problem is how to populate the body?

I tried

CodeTypeMember mem = new CodeTypeMember();
mem.Name = WadlSharpUtils.CreateIdentifier(discreteValue.value);
mem.CustomAttributes.Add(new CodeAttributeDeclaration(discreteValue.value));
// enumCandidate is an instance of CodeTypeDeclaration
enumCandidate.Members.Add(mem);

Though using this solution I can generate the Description attributes, the end of line would be ; and not ,

© Stack Overflow or respective owner

Related posts about codedom

Related posts about c#