I want to create a C# fileGenerator,so i dowload the samples and learn from video.
https://channel9.msdn.com/Blogs/MVP-Windows-Dev/Learn-Roslyn-Now-E06-MSBuildWorkspace
But when I use GetService method to get workspace,it returns null.
public class NFinalControllerGenerator :BaseCodeGeneratorWithSite { public VisualStudioWorkspace visualStuioWorkspace = null; internal static string name = "NFinalControllerGenerator"; protected override byte[] GenerateCode(string inputFileContent) { var componentModel = (IComponentModel)this.GetServiceObject(typeof(SComponentModel)); if (componentModel != null) { visualStuioWorkspace = componentModel.GetService<Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>(); } return System.Text.Encoding.UTF8.GetBytes("Hello World!"); } }
It's something wrong?
My goal is to Generate serveral new C# class from old file, that has all Fields and Propertys.