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


C# AssemblyName.FirstOrDefault方法代码示例

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


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

示例1: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			if (this.References.Length == 0 || this.Projects.Length == 0) {
				this.Log.LogMessage(MessageImportance.Low, "Skipping reference hintpath fixup because no projects or no references were supplied.");
				return !this.Log.HasLoggedErrors;
			}

			// Figure out what the assembly names are of the references that are available.
			AssemblyName[] availableReferences = new AssemblyName[this.References.Length];
			for (int i = 0; i < this.References.Length; i++) {
				if (File.Exists(this.References[i].ItemSpec)) {
					availableReferences[i] = AssemblyName.GetAssemblyName(this.References[i].ItemSpec);
				} else {
					availableReferences[i] = new AssemblyName(Path.GetFileNameWithoutExtension(this.References[i].ItemSpec)) {
						CodeBase = this.References[i].GetMetadata("FullPath"),
					};
				}
			}

			foreach (var projectTaskItem in this.Projects) {
				var project = new Project();
				Uri projectUri = new Uri(projectTaskItem.GetMetadata("FullPath"));
				project.Load(projectTaskItem.ItemSpec);

				foreach (BuildItem referenceItem in project.GetEvaluatedItemsByName("Reference")) {
					var referenceAssemblyName = new AssemblyName(referenceItem.Include);
					var matchingReference = availableReferences.FirstOrDefault(r => string.Equals(r.Name, referenceAssemblyName.Name, StringComparison.OrdinalIgnoreCase));
					if (matchingReference != null) {
						var originalSuppliedReferenceItem = this.References[Array.IndexOf(availableReferences, matchingReference)];
						string hintPath = originalSuppliedReferenceItem.GetMetadata("HintPath");
						if (string.IsNullOrEmpty(hintPath)) {
							hintPath = projectUri.MakeRelativeUri(new Uri(matchingReference.CodeBase)).OriginalString.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
						}
						this.Log.LogMessage("Fixing up HintPath to \"{0}\" in project \"{1}\".", referenceAssemblyName.Name, projectTaskItem.ItemSpec);
						referenceItem.SetMetadata("HintPath", hintPath);
					}
				}

				project.Save(projectTaskItem.ItemSpec);
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:45,代码来源:FixupReferenceHintPaths.cs


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