/// <summary> /// 创建 <see cref="CompileFile"/> 的新实例,通过此实例可以获取文件中的相关类型信息。 /// </summary> /// <param name="fullName"></param> public CompileFile(string fullName) { FullName = fullName; Name = Path.GetFileName(fullName); var originalText = File.ReadAllText(fullName); _syntaxTree = CSharpSyntaxTree.ParseText(originalText); var compileTypeVisitor = new CompileTypeVisitor(); compileTypeVisitor.Visit(_syntaxTree.GetRoot()); Types = compileTypeVisitor.Types.ToList(); }
/// <summary> /// 创建 <see cref="CompileFile"/> 的新实例,通过此实例可以获取文件中的相关类型信息。 /// </summary> /// <param name="context"></param> /// <param name="fullName"></param> /// <param name="preprocessorSymbols"></param> public CompileFile(CompilingContext context, string fullName, IEnumerable <string> preprocessorSymbols) { _context = context; FullName = fullName; Name = Path.GetFileName(fullName); var originalText = File.ReadAllText(fullName); _syntaxTree = CSharpSyntaxTree.ParseText(originalText, new CSharpParseOptions( LanguageVersion.Latest, DocumentationMode.None, SourceCodeKind.Regular, preprocessorSymbols)); var compileTypeVisitor = new CompileTypeVisitor(); compileTypeVisitor.Visit(_syntaxTree.GetRoot()); Types = compileTypeVisitor.Types.ToList(); UsingNamespaceList = compileTypeVisitor.UsingNamespaceList; AssemblyAttributes = compileTypeVisitor.AssemblyAttributes.ToList(); }