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


C# ICompilationUnit.Any方法代码示例

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


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

示例1: ParseFile

			public ParseInformation ParseFile(IProjectContent parentProjectContent, ITextBuffer fileContent)
			{
				if (parser == null)
					return null;
				
				if (fileContent == null) {
					// GetParseableFileContent must not be called inside any lock
					// (otherwise we'd risk deadlocks because GetParseableFileContent must invoke on the main thread)
					fileContent = GetParseableFileContent(fileName);
				}
				
				ITextBufferVersion fileContentVersion = fileContent.Version;
				List<IProjectContent> projectContents;
				lock (this) {
					if (this.disposed)
						return null;
					
					if (fileContentVersion != null && this.bufferVersion != null && this.bufferVersion.BelongsToSameDocumentAs(fileContentVersion)) {
						if (this.bufferVersion.CompareAge(fileContentVersion) >= 0) {
							// Special case: (necessary due to parentProjectContent optimization)
							// Detect when a file belongs to multiple projects but the ParserService hasn't realized
							// that, yet. In this case, do another parse run to detect all parent projects.
							if (!(parentProjectContent != null && this.oldUnits.Length == 1 && this.oldUnits[0].ProjectContent != parentProjectContent)) {
								return this.parseInfo;
							}
						}
					}
					
					if (parentProjectContent != null && (oldUnits.Length == 0 || (oldUnits.Length == 1 && oldUnits[0].ProjectContent == parentProjectContent))) {
						// Optimization: if parentProjectContent is specified and doesn't conflict with what we already know,
						// we will use it instead of doing an expensive GetProjectContents call.
						projectContents = new List<IProjectContent>();
						projectContents.Add(parentProjectContent);
					} else {
						projectContents = GetProjectContents(fileName);
					}
				}
				// We now leave the lock to do the actual parsing.
				// This is done to allow IParser implementations to invoke methods on the main thread without
				// risking deadlocks.
				
				// parse once for each project content that contains the file
				ICompilationUnit[] newUnits = new ICompilationUnit[projectContents.Count];
				ICompilationUnit resultUnit = null;
				for (int i = 0; i < newUnits.Length; i++) {
					IProjectContent pc = projectContents[i];
					try {
						newUnits[i] = parser.Parse(pc, fileName, fileContent);
					} catch (Exception ex) {
						throw new ApplicationException("Error parsing " + fileName, ex);
					}
					if (i == 0 || pc == parentProjectContent)
						resultUnit = newUnits[i];
				}
				lock (this) {
					if (this.disposed)
						return null;
					
					// ensure we never go backwards in time (we need to repeat this check after we've reacquired the lock)
					if (fileContentVersion != null && this.bufferVersion != null && this.bufferVersion.BelongsToSameDocumentAs(fileContentVersion)) {
						if (this.bufferVersion.CompareAge(fileContentVersion) >= 0) {
							if (parentProjectContent != null && parentProjectContent != parseInfo.CompilationUnit.ProjectContent) {
								ICompilationUnit oldUnit = oldUnits.FirstOrDefault(o => o.ProjectContent == parentProjectContent);
								if (oldUnit != null)
									return new ParseInformation(oldUnit);
							}
							return this.parseInfo;
						}
					}
					
					ParseInformation newParseInfo = new ParseInformation(resultUnit);
					
					for (int i = 0; i < newUnits.Length; i++) {
						IProjectContent pc = projectContents[i];
						// update the compilation unit
						ICompilationUnit oldUnit = oldUnits.FirstOrDefault(o => o.ProjectContent == pc);
						pc.UpdateCompilationUnit(oldUnit, newUnits[i], fileName);
						ParseInformation newUnitParseInfo = (newUnits[i] == resultUnit) ? newParseInfo : new ParseInformation(newUnits[i]);
						RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, pc, oldUnit, newUnitParseInfo));
					}
					
					// remove all old units that don't exist anymore
					foreach (ICompilationUnit oldUnit in oldUnits) {
						if (!newUnits.Any(n => n.ProjectContent == oldUnit.ProjectContent)) {
							oldUnit.ProjectContent.RemoveCompilationUnit(oldUnit);
							RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, oldUnit.ProjectContent, oldUnit, null));
						}
					}
					
					this.bufferVersion = fileContentVersion;
					this.oldUnits = newUnits;
					this.parseInfo = newParseInfo;
					return newParseInfo;
				}
			}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:95,代码来源:ParserService.cs


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