1

我正在尝试编写一个源生成器来删除项目中的样板代码。该项目的目的是从“解决方案”代码的现有单元测试中为“练习”代码生成新的单元测试。我将在下面给出一个简短的示例:

// The "solution" code
public void Name_InitializesAsNull() {
  Solutions.Person person = new Solutions.Person();
  Assert.IsNull(person.Name);
}

// The "exercise" code
public void Name_InitializesAsNull() {
  Exercises.Person person = new Exercise.Person();
  Assert.IsNull(person.Name);
}

为了生成这个附加方法,我想验证Exercises.Person 类是否具有可读字段或属性名称。我以前通过反思做到了这一点,并希望继续这样做。

所以我的问题是:是否可以在 CSharpCompilation.ExternalReferences 指定的程序集中类型的源生成期间访问类型信息,如 MemberInfo?

4

0 回答 0