Refer custom class in the Auto generated class?

107 Views Asked by At

I've two classes that I am trying to generate code using CodeDom. First class (StudentModel), pretty straight forward, I am able to generate using CodeDom.

In the second class, i.e. Student class, I am trying refer StudentModel class. StudentModel class will be generated before Generating Student class.

But is it possible to generate second class (Student) using CodeDom???

public class StudentModel
{
  public string Name { get; set; }
}

public class Student
{

    void AddStudent(StudentModel model);
}
1

There are 1 best solutions below

0
On

I think you simply need to use the name of the first type to generate the method:

CodeTypeDeclaration studentModelClass = …;

var addStudentMethod =
    new CodeMemberMethod
    {
        Name = "AddStudent",
        Parameters =
        {
            new CodeParameterDeclarationExpression(studentClass.Name, "student")
        }
    };