本文整理汇总了C#中IProjectContent.AddOrUpdateFiles方法的典型用法代码示例。如果您正苦于以下问题:C# IProjectContent.AddOrUpdateFiles方法的具体用法?C# IProjectContent.AddOrUpdateFiles怎么用?C# IProjectContent.AddOrUpdateFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProjectContent
的用法示例。
在下文中一共展示了IProjectContent.AddOrUpdateFiles方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
void Init(string program)
{
pc = new CSharpProjectContent();
pc = pc.SetAssemblyName("MyAssembly");
unresolvedFile = SyntaxTree.Parse(program, "program.cs").ToTypeSystem();
pc = pc.AddOrUpdateFiles(unresolvedFile);
pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });
compilation = pc.CreateCompilation();
}
示例2: CSharpCodeCompletionContext
public CSharpCodeCompletionContext(IDocument document, int offset, IProjectContent projectContent) {
this.document = new ReadOnlyDocument(document, document.FileName);
this.offset = offset;
var unresolvedFile = CSharpParsingHelpers.CreateCSharpUnresolvedFile(this.document);
this.projectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
completionContextProvider = new DefaultCompletionContextProvider(this.document, unresolvedFile);
var compilation = this.projectContent.CreateCompilation();
var location = this.document.GetLocation(this.offset);
typeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(compilation, location);
}
示例3: SetUp
public void SetUp()
{
pc = new CSharpProjectContent();
pc = pc.SetAssemblyName("MyAssembly");
unresolvedFile = SyntaxTree.Parse(program, "program.cs").ToTypeSystem();
pc = pc.AddOrUpdateFiles(unresolvedFile);
pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib });
compilation = pc.CreateCompilation();
baseClass = compilation.RootNamespace.GetTypeDefinition("Base", 1);
nestedClass = baseClass.NestedTypes.Single();
derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2);
systemClass = compilation.RootNamespace.GetChildNamespace("NS").GetTypeDefinition("System", 0);
}
示例4: CSharpCompletionContext
/// <summary>
/// Initializes a new instance of the <see cref="CSharpCompletionContext"/> class.
/// </summary>
/// <param name="document">The document, make sure the FileName property is set on the document.</param>
/// <param name="offset">The offset.</param>
/// <param name="projectContent">Content of the project.</param>
/// <param name="usings">The usings.</param>
public CSharpCompletionContext(IDocument document, int offset, IProjectContent projectContent, string usings = null)
{
OriginalDocument = document;
OriginalOffset = offset;
//if the document is a c# script we have to soround the document with some code.
Document = PrepareCompletionDocument(document, ref offset, usings);
Offset = offset;
var syntaxTree = new CSharpParser().Parse(Document, Document.FileName);
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
//note: it's important that the project content is used that is returned after adding the unresolved file
Compilation = ProjectContent.CreateCompilation();
var location = Document.GetLocation(Offset);
Resolver = unresolvedFile.GetResolver(Compilation, location);
TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(Compilation, location);
CompletionContextProvider = new DefaultCompletionContextProvider(Document, unresolvedFile);
}
示例5: AddCompileFilesToProject
private IProjectContent AddCompileFilesToProject(Project msbuildProject, IProjectContent pc)
{
foreach (var item in msbuildProject.GetItems("Compile"))
{
var filepath = Path.Combine(msbuildProject.DirectoryPath, item.EvaluatedInclude);
if (File.Exists(filepath))
{
var file = new CSharpFile(this, filepath);
Files.Add(file);
}
}
pc = pc.AddOrUpdateFiles(Files.Select(f => f.UnresolvedTypeSystemForFile));
return pc;
}
示例6: FindReferences
public override IEnumerable<MemberReference> FindReferences (Project project, IProjectContent content, IEnumerable<FilePath> possibleFiles, IEnumerable<object> members)
{
if (content == null)
throw new ArgumentNullException ("content", "Project content not set.");
SetPossibleFiles (possibleFiles);
SetSearchedMembers (members);
var scopes = searchedMembers.Select (e => refFinder.GetSearchScopes (e as IEntity));
var compilation = project != null ? TypeSystemService.GetCompilation (project) : content.CreateCompilation ();
List<MemberReference> refs = new List<MemberReference> ();
foreach (var opendoc in openDocuments) {
foreach (var newRef in FindInDocument (opendoc.Item2)) {
if (newRef == null || refs.Any (r => r.FileName == newRef.FileName && r.Region == newRef.Region))
continue;
refs.Add (newRef);
}
}
foreach (var file in files) {
string text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (file);
if (memberName != null && text.IndexOf (memberName, StringComparison.Ordinal) < 0 &&
(keywordName == null || text.IndexOf (keywordName, StringComparison.Ordinal) < 0))
continue;
using (var editor = TextEditorData.CreateImmutable (text)) {
editor.Document.FileName = file;
var unit = new PlayScriptParser ().Parse (editor);
if (unit == null)
continue;
var storedFile = content.GetFile (file);
var parsedFile = storedFile as CSharpUnresolvedFile;
if (parsedFile == null && storedFile is ParsedDocumentDecorator) {
parsedFile = ((ParsedDocumentDecorator)storedFile).ParsedFile as CSharpUnresolvedFile;
}
if (parsedFile == null) {
// for fallback purposes - should never happen.
parsedFile = unit.ToTypeSystem ();
content = content.AddOrUpdateFiles (parsedFile);
compilation = content.CreateCompilation ();
}
foreach (var scope in scopes) {
refFinder.FindReferencesInFile (
scope,
parsedFile,
unit,
compilation,
(astNode, result) => {
var newRef = GetReference (result, astNode, file, editor);
if (newRef == null || refs.Any (r => r.FileName == newRef.FileName && r.Region == newRef.Region))
return;
refs.Add (newRef);
},
CancellationToken.None
);
}
}
}
return refs;
}
示例7: AnalyzeFile
void AnalyzeFile (ProjectFile file, IProjectContent content)
{
var me = new object ();
var owner = processedFiles.AddOrUpdate (file.Name, me, (key, old) => old);
if (me != owner)
return;
if (file.BuildAction != BuildAction.Compile || tokenSource.IsCancellationRequested)
return;
TextEditorData editor;
try {
editor = TextFileProvider.Instance.GetReadOnlyTextEditorData (file.FilePath);
} catch (FileNotFoundException) {
// Swallow exception and ignore this file
return;
}
var document = TypeSystemService.ParseFile (file.Project, editor);
if (document == null)
return;
var compilation = content.AddOrUpdateFiles (document.ParsedFile).CreateCompilation ();
CSharpAstResolver resolver;
using (var timer = ExtensionMethods.ResolveCounter.BeginTiming ()) {
resolver = new CSharpAstResolver (compilation, document.GetAst<SyntaxTree> (), document.ParsedFile as ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpUnresolvedFile);
resolver.ApplyNavigator (new ExtensionMethods.ConstantModeResolveVisitorNavigator (ResolveVisitorNavigationMode.Resolve, null));
}
var context = document.CreateRefactoringContextWithEditor (editor, resolver, tokenSource.Token);
var codeIssueProviders = RefactoringService.GetInspectors (editor.MimeType)
.SelectMany (p => p.GetEffectiveProviderSet ())
.ToList ();
foreach (var provider in codeIssueProviders) {
var severity = provider.GetSeverity ();
if (severity == Severity.None || !provider.GetIsEnabled () || tokenSource.IsCancellationRequested)
continue;
try {
foreach (var issue in provider.GetIssues (context, tokenSource.Token)) {
AddIssue (file, provider, issue);
}
} catch (OperationCanceledException) {
// The operation was cancelled, no-op as the user-visible parts are
// handled elsewhere
}
}
}
示例8: CSharpProject
public CSharpProject(
ICSharpFileFactory cSharpFileFactory,
MicrosoftBuildProject msBuildProject,
string title)
{
Title = title;
AssemblyName = msBuildProject.AssemblyName;
FileName = msBuildProject.FileName;
CompilerSettings =
#region new CompilerSettings
new CompilerSettings
{
AllowUnsafeBlocks = msBuildProject.AllowUnsafeBlocks,
CheckForOverflow = msBuildProject.CheckForOverflowUnderflow,
};
CompilerSettings.ConditionalSymbols.AddRange(msBuildProject.DefineConstants);
#endregion
ProjectContent = new CSharpProjectContent();
ProjectContent = ProjectContent.SetAssemblyName(msBuildProject.AssemblyName);
ProjectContent = ProjectContent.SetProjectFileName(msBuildProject.FileName.FullPath);
ProjectContent = ProjectContent.SetCompilerSettings(CompilerSettings);
Files = msBuildProject.CompiledFileNames.Select(
f => cSharpFileFactory.BuildCSharpFile(this, new FilePath(f))).ToList();
ProjectContent = ProjectContent.AddOrUpdateFiles(
Files.Select(f => f.UnresolvedTypeSystemForFile));
ProjectContent = ProjectContent.AddAssemblyReferences(msBuildProject.ReferencedAssemblies);
}