/// <summary> /// This is overridden to allow proper comparison of assembly detail objects /// </summary> /// <param name="obj">The object to which this instance is compared</param> /// <returns>Returns true if the object equals this instance, false if it does not</returns> public override bool Equals(object obj) { if (obj == null || obj.GetType() != this.GetType()) { return(false); } AssemblyDetails otherDetails = obj as AssemblyDetails; return(this.ToString().Equals(otherDetails.ToString(), StringComparison.Ordinal)); }
//===================================================================== /// <summary> /// This can be used to load an empty location with information about the assemblies it contains /// </summary> /// <remarks>If the location already has assembly details, it will do nothing.</remarks> public void DetermineAssemblyDetails() { if (assemblyDetails.Count == 0 && Directory.Exists(this.Path)) { foreach (string assembly in Directory.EnumerateFiles(this.Path, "*.dll").Concat( Directory.EnumerateFiles(this.Path, "*.winmd"))) { try { assemblyDetails.Add(AssemblyDetails.FromAssemblyName( AssemblyName.GetAssemblyName(assembly))); } catch (BadImageFormatException ex) { // Ignore, not a .NET assembly System.Diagnostics.Debug.WriteLine(ex.FileName); } } } }
//===================================================================== /// <summary> /// This is used to load the settings for an assembly location from an XML element /// </summary> /// <param name="location">The XML element containing the settings</param> /// <returns>The new assembly location item</returns> /// <remarks>If the location element is empty, the assembly details will be created by scanning the /// location for assemblies.</remarks> internal static AssemblyLocation FromXml(XElement location) { string path = Environment.ExpandEnvironmentVariables(location.Attribute("Path").Value); // If x86 but it didn't exist, assume it's a 32-bit system and change the name if (path.IndexOf("%ProgramFiles(x86)%", StringComparison.Ordinal) != -1) { path = Environment.ExpandEnvironmentVariables(path.Replace("(x86)", String.Empty)); } AssemblyLocation al = new AssemblyLocation { Path = path, IsCoreLocation = ((bool?)location.Attribute("IsCore") ?? false) }; foreach (var a in location.Descendants("AssemblyDetails")) { al.assemblyDetails.Add(AssemblyDetails.FromXml(path, a)); } return(al); }