0

I need to generate nested classes using CodeDom. But I could not find any option to add a class( CodeTypeDeclaration) to another class as member.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by __avd
0

>But I could not find any option to add a class( CodeTypeDeclaration) to another class as member.

CodeNamespace ns = new CodeNamespace("com.me");
        ns.Imports.Add(new CodeNamespaceImport("System"));

        CodeTypeDeclaration class1 = new CodeTypeDeclaration("Student");
        CodeTypeDeclaration class2 = new CodeTypeDeclaration("Marks");
        
        class2.IsClass =true;
        class2.TypeAttributes = System.Reflection.TypeAttributes.NestedPublic;
        
        class1.Members.Add(class2);
        ns.Types.Add(class1 );
        CodeDomProvider pv = CodeDomProvider.CreateProvider("C#");
        ICodeGenerator g = pv.CreateGenerator();
        g.GenerateCodeFromNamespace(ns, Console.Out, new CodeGeneratorOptions());
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.