当前位置: 首页>>代码示例>>C#>>正文


C# Project.AddDocument方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.Project.AddDocument方法的典型用法代码示例。如果您正苦于以下问题:C# Project.AddDocument方法的具体用法?C# Project.AddDocument怎么用?C# Project.AddDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.Project的用法示例。


在下文中一共展示了Project.AddDocument方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CSharpCompilerModule

 /// <summary>
 /// Initializes a new instance of the <see cref="CsvCompilerModule"/> class.
 /// </summary>
 public CSharpCompilerModule(Bootstrapper bootstrapper)
     : base(bootstrapper)
 {
     compiler = new CSharpCompiler();
     workspace = new AdhocWorkspace();
     project = workspace.AddProject("CSharpProject", LanguageNames.CSharp);
     document = project.AddDocument("current", "");
     context = new CompilationContext(workspace, document);
 }
开发者ID:szabototo89,项目名称:CodeSharper,代码行数:12,代码来源:CSharpCompilerModule.cs

示例2: GetDocumentFromMetadata

        public static Task<Document> GetDocumentFromMetadata(Project project, ISymbol symbol, CancellationToken cancellationToken = new CancellationToken())
        {
            var filePath = GetFilePathForSymbol(project, symbol);
            var topLevelSymbol = GetTopLevelContainingNamedType(symbol);
            var temporaryDocument = project.AddDocument(filePath, string.Empty);

            object service = Activator.CreateInstance(_CSharpMetadataAsSourceService.Value, new object[] { temporaryDocument.Project.LanguageServices });
            var method = _CSharpMetadataAsSourceService.Value.GetMethod("AddSourceToAsync");

            return (Task<Document>)method.Invoke(service, new object[] { temporaryDocument, topLevelSymbol, cancellationToken });
        }
开发者ID:azhoshkin,项目名称:omnisharp-roslyn,代码行数:11,代码来源:MetadataHelper.cs

示例3: AddPathToProject

        private static void AddPathToProject(ref Solution solution, ref Project project, string fileName, string contents)
        {
            var document = GetExistingDocument(project, fileName);
            if (document != null)
            {
                project = project.RemoveDocument(document.Id);
                solution = project.Solution;
            }

            Console.WriteLine($"\t - Adding {fileName} to project");
            document = project.AddDocument(fileName,
                contents,
                null,
                Path.Combine(Path.GetDirectoryName(project.FilePath), fileName));
            project = document.Project;
            solution = project.Solution;
        }
开发者ID:ffMathy,项目名称:pinvoke-1,代码行数:17,代码来源:Program.cs

示例4: CompileHandlebarsFiles

 private static Workspace CompileHandlebarsFiles(Project project, Workspace workspace, List<string> hbsFiles, CompilerOptions options)
 {
     bool successFullCompilation = true;
       while(hbsFiles.Any() && successFullCompilation)
       {
     successFullCompilation = false;
     var nextRound = new List<string>();
     foreach(var file in hbsFiles)
     {
       var fileInfo = new FileInfo(file);
       string @namespace;
       bool compiledVersionExists = File.Exists($"{file}.cs");
       bool compiledVersionIsOlder = true;
       if (compiledVersionExists)
       {//Compiled Version already exists
     var compiledFileInfo = new FileInfo($"{file}.cs");
     compiledVersionIsOlder = (fileInfo.LastWriteTimeUtc > compiledFileInfo.LastWriteTimeUtc);
     @namespace = DetermineNamespace(compiledFileInfo);
       } else
       {
     @namespace = DetermineNamespace(fileInfo, project);
       }
       if (compiledVersionIsOlder || options.ForceRecompilation)
       {
     string content = File.ReadAllText(file);
     string name = Path.GetFileNameWithoutExtension(file);
     var compilationResult = CompileHandlebarsTemplate(content, @namespace, name, project, options);
     if (!options.DryRun)
     {
       if (compilationResult?.Item2?.Any() ?? false)
       {//Errors occured
         if (compilationResult.Item2.OfType<HandlebarsTypeError>().Any(x => x.Kind == HandlebarsTypeErrorKind.UnknownPartial))
         {//Unresolvable Partial... could be due to compiling sequence
           //Console.WriteLine($"Unresolved partial call for template '{name}'. Try again!");
           nextRound.Add(file);
         }
         else
           foreach (var error in compilationResult.Item2)
             PrintError(error);
       }
       else
       {
         successFullCompilation = true;
         //Check if template already exits
         var doc = project.Documents.FirstOrDefault(x => x.Name.Equals(string.Concat(name, ".hbs.cs")));
         if (doc != null)
         {//And change it if it does
           project = doc.WithSyntaxRoot(CSharpSyntaxTree.ParseText(SourceText.From(compilationResult.Item1)).GetRoot()).Project;
         }
         else
         {//Otherwise add a new document
           project = project.AddDocument(string.Concat(name, ".hbs.cs"), SourceText.From(compilationResult.Item1), GetFolderStructureForFile(fileInfo, project)).Project;
         }
         try {
           workspace.TryApplyChanges(project.Solution);
           project = workspace.CurrentSolution.Projects.First(x => x.Id.Equals(project.Id));
         } catch(NotSupportedException)
         {//ProjectJsonWorkspace does not support adding documents (as of 2016-02-17). So just add it manually
           File.WriteAllText($"{file}.cs", compilationResult.Item1);
         }
       }
     }
       }
     }
     hbsFiles = nextRound;
       }
       return workspace;
 }
开发者ID:Noxum,项目名称:CompiledHandlebars,代码行数:68,代码来源:Program.cs

示例5: MoveTypeNodes

		private static Project MoveTypeNodes(SemanticModel model, ImmutableArray<TypeToRemove> typesToRemove,
			Func<string, string> typeFolderGenerator, Project project, CancellationToken token)
		{
			var projectName = project.Name;

			foreach (var typeToRemove in typesToRemove)
			{
				token.ThrowIfCancellationRequested();
				var fileName = $"{typeToRemove.Symbol.Name}.cs";

				var containingNamespace = typeToRemove.Symbol.GetContainingNamespace();
				var typeFolder = typeFolderGenerator(containingNamespace).Replace(
					projectName, string.Empty);

				if (typeFolder.StartsWith("\\"))
				{
					typeFolder = typeFolder.Remove(0, 1);
				}

				project = project.AddDocument(fileName,
					typeToRemove.Declaration.GetCompilationUnitForType(model, containingNamespace),
					folders: !string.IsNullOrWhiteSpace(typeFolder) ?
						new[] { typeFolder } : null).Project;
			}

			return project;
		}
开发者ID:JasonBock,项目名称:CompilerAPIBook,代码行数:27,代码来源:ExtractTypesToFilesCodeRefactoringProvider.cs

示例6: AddDocument

        private static Project AddDocument(
            Project project,
            KeyValuePair<INamedTypeSymbol, string> symbolAndText,
            HashSet<string> existingFileNames)
        {
            var symbol = symbolAndText.Key;
            var text = symbolAndText.Value;
            var sanitizedTypeName = Paths.SanitizeFileName(symbol.Name);
            if (symbol.IsGenericType)
            {
                sanitizedTypeName = sanitizedTypeName + "`" + symbol.TypeParameters.Length;
            }

            var fileName = sanitizedTypeName + ".cs";
            var folders = GetFolderChain(symbol);
            if (folders == null)
            {
                // There was an unutterable namespace name - abort the entire document
                return null;
            }

            var foldersString = string.Join(".", folders ?? Enumerable.Empty<string>());
            var fileNameAndFolders = foldersString + fileName;
            int index = 1;
            while (!existingFileNames.Add(fileNameAndFolders))
            {
                fileName = sanitizedTypeName + index + ".cs";
                fileNameAndFolders = foldersString + fileName;
                index++;
            }

            project = project.AddDocument(fileName, text, folders, fileName).Project;
            return project;
        }
开发者ID:KirillOsenkov,项目名称:SourceBrowser,代码行数:34,代码来源:MetadataAsSource.cs

示例7: AddDocument

 protected override Project AddDocument(Project fromProject)
     => fromProject.AddDocument(DocumentInfo.Name, Text, DocumentInfo.Folders, DocumentInfo.FilePath).Project;
开发者ID:TyOverby,项目名称:roslyn,代码行数:2,代码来源:VisualStudioWorkspaceImpl.AddDocumentUndoUnit.cs


注:本文中的Microsoft.CodeAnalysis.Project.AddDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。