static string GetAssemblyFile(AssemblyNameInfo reference, string prefix, string gac) { var gac_folder = new StringBuilder() .Append(prefix) .Append(reference.Version) .Append("__"); var pkt = PublicKeyBase.ToPublicKeyToken(reference.PublicKeyOrToken); if (PublicKeyBase.IsNullOrEmpty2(pkt)) { pkt = new PublicKeyToken(new byte[8]); } for (int i = 0; i < pkt.Data.Length; i++) { gac_folder.Append(pkt.Data [i].ToString("x2")); } try { return(Path.Combine( Path.Combine( Path.Combine(gac, reference.Name), gac_folder.ToString()), reference.Name + ".dll")); } catch (ArgumentException) { } return(null); }
public bool Matches(CanonicalName packageCriteria) { if (null == packageCriteria) { return(false); } if (IsPartial) { throw new CoAppException("CanonicalName.Matches() may not be called on a Partial Package Name."); } // looking for a single package if (packageCriteria.IsCanonical) { return(Equals(packageCriteria)); } return(PackageType == packageCriteria.PackageType && Name.NewIsWildcardMatch(packageCriteria.Name) && Flavor.IsWildcardMatch(packageCriteria.Flavor) && (Version == packageCriteria.Version || (packageCriteria.MatchVersionOrGreater && Version > packageCriteria.Version)) && (packageCriteria.Architecture == Architecture.Auto || packageCriteria.Architecture == Architecture) && PublicKeyToken.NewIsWildcardMatch(packageCriteria.PublicKeyToken)); }
static IEnumerable <string> GetAssemblies(GacDirInfo gacInfo, PublicKeyToken pkt, IAssembly assembly) { string pktString = pkt.ToString(); string verString = assembly.Version.ToString(); var cultureString = UTF8String.ToSystemStringOrEmpty(assembly.Culture); if (cultureString.Equals("neutral", StringComparison.OrdinalIgnoreCase)) { cultureString = string.Empty; } var asmSimpleName = UTF8String.ToSystemStringOrEmpty(assembly.Name); foreach (var subDir in gacInfo.SubDirs) { var baseDir = Path.Combine(gacInfo.Path, subDir); string pathName; try { baseDir = Path.Combine(baseDir, asmSimpleName); baseDir = Path.Combine(baseDir, $"{gacInfo.Prefix}{verString}_{cultureString}_{pktString}"); pathName = Path.Combine(baseDir, asmSimpleName + ".dll"); } catch (ArgumentException) { // Invalid char(s) in asmSimpleName, cultureString yield break; } if (File.Exists(pathName)) { yield return(pathName); } } }
public override string ToString() { var sb = new StringBuilder(); sb.Append(Name); if (Version != null) { sb.AppendFormat(", Version = {0}", Version); } sb.AppendFormat(", Culture = {0}", string.IsNullOrEmpty(Culture) ? "neutral" : Culture); sb.Append(", PublicKeyToken = "); if (!PublicKeyToken.IsNullOrEmpty()) { sb.Append(BitConverter.ToString(PublicKeyToken) .Replace("-", "") .ToLower()); } else { sb.Append("null"); } return(sb.ToString()); }
/// <summary> /// Compares two <see cref="PublicKeyToken"/>s /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns>< 0 if a < b, 0 if a == b, > 0 if a > b</returns> public static int TokenCompareTo(PublicKeyToken a, PublicKeyToken b) { if (a == b) { return(0); } return(TokenCompareTo(a == null ? null : a.data, b == null ? null : b.data)); }
/// <summary> /// Gets the public key token hash code /// </summary> /// <param name="a">Public key token</param> /// <returns>The hash code</returns> public static int GetHashCode(PublicKeyToken a) { if (a == null) { return(0); } return(Utils.GetHashCode(a.Data)); }
public AssemblyReferenceInformation(string name, Version version, string culture, PublicKeyToken publicKeyToken) { Name = name; Version = version; Culture = culture; PublicKeyToken = publicKeyToken; _string = string.Format(CultureInfo.CurrentCulture, LocalizedStrings.AssemblyReferenceInformation, Name, Version, Culture, PublicKeyToken); }
public override int GetHashCode() { unchecked { var hashCode = (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (PublicKeyToken != null ? PublicKeyToken.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Culture != null ? Culture.GetHashCode() : 0); return(hashCode); } }
static bool IsPublicKeyToken(PublicKeyToken[] tokens, PublicKeyToken token) { foreach (var t in tokens) { if (token.Equals(t)) { return(true); } } return(false); }
public bool IsFrameworkAssembly(string name, PublicKeyToken publicKeyToken) { if (string.IsNullOrEmpty(name)) { return(false); } var result = string.Equals(_assemblyName, name, StringComparison.Ordinal) || SystemObjectAssemblies.Contains(name) || _frameworkAssemblies.Contains(name); return(result); }
public AssemblyInfo(AssemblyName assemblyName) { Name = assemblyName.Name; Version = assemblyName.Version.ToString(); RuntimeVersion = ""; Platform = assemblyName.ProcessorArchitecture.ToString(); CultureInfo = assemblyName.CultureInfo; PublicKeyToken = assemblyName.GetPublicKeyToken(); if (PublicKeyToken == null || PublicKeyToken.Length == 0) { PublicKeyTokenString = null; } else { PublicKeyTokenString = string.Join(string.Empty, PublicKeyToken.Select(b => b.ToString("X2"))); } }
static IEnumerable <string> GetAssemblies(GacDirInfo gacInfo, PublicKeyToken pkt, IAssembly assembly) { string pktString = pkt.ToString(); string verString = assembly.Version.ToString(); var cultureString = UTF8String.ToSystemStringOrEmpty(assembly.Culture); if (cultureString.Equals("neutral", StringComparison.OrdinalIgnoreCase)) { cultureString = string.Empty; } var asmSimpleName = UTF8String.ToSystemStringOrEmpty(assembly.Name); foreach (var subDir in gacInfo.SubDirs) { var baseDir = Path.Combine(gacInfo.Path, subDir); baseDir = Path.Combine(baseDir, asmSimpleName); baseDir = Path.Combine(baseDir, string.Format("{0}{1}_{2}_{3}", gacInfo.Prefix, verString, cultureString, pktString)); var pathName = Path.Combine(baseDir, asmSimpleName + ".dll"); if (File.Exists(pathName)) { yield return(pathName); } } }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { // As obtained from the Jon Skeet answer to: // http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode // And adapted towards the Modified Bernstein (shown here: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx) // // Overflow is fine, just wrap unchecked { // Pick a random prime number int hash = 17; // Mash the hash together with yet another random prime number hash = (hash * 23) ^ Name.GetHashCode(); hash = (hash * 23) ^ Version.GetHashCode(); hash = (hash * 23) ^ Culture.GetHashCode(); if (PublicKeyToken != null) { hash = (hash * 23) ^ PublicKeyToken.GetHashCode(); } return(hash); } }
/// <summary> /// Checks whether two public key tokens are equal /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns><c>true</c> if same, <c>false</c> otherwise</returns> public static bool TokenEquals(PublicKeyToken a, PublicKeyToken b) { return(TokenCompareTo(a, b) == 0); }
private string PublicKeyTokenAsString() { return(PublicKeyToken != null ? string.Join(string.Empty, PublicKeyToken.Select(b => b.ToString("x2")).ToArray()) : string.Empty); }
/// <summary> /// Gets the public key token hash code /// </summary> /// <param name="a">Public key token</param> /// <returns>The hash code</returns> public static int GetHashCode(PublicKeyToken a) { if (a == null) return 0; return Utils.GetHashCode(a.Data); }
/// <summary> /// Checks whether two public key tokens are equal /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns><c>true</c> if same, <c>false</c> otherwise</returns> public static bool TokenEquals(PublicKeyToken a, PublicKeyToken b) { return TokenCompareTo(a, b) == 0; }
public override bool IsFrameworkMember(string name, PublicKeyToken publicKeyToken) { return(string.Equals(_name, name, StringComparison.OrdinalIgnoreCase)); }
public void InvalidPublicKeyToken(string publicKeyToken) { Assert.Throws <PortabilityAnalyzerException>(() => _assemblyFilter.IsFrameworkAssembly(string.Empty, PublicKeyToken.Parse(publicKeyToken))); }
public bool IsFrameworkAssembly(string name, PublicKeyToken publicKeyToken) { return(IsKnownPublicKeyToken(publicKeyToken) || IsKnownName(name)); }
/// <summary> /// Builds full name of the project reference. /// </summary> /// <returns>Full name.</returns> private string BuildFullName() { StringBuilder builder = new StringBuilder(AssemblyName).Append(", "); builder.Append(VersionField).Append("=").Append(Version).Append(", "); builder.Append(CultureField).Append("=").Append(Culture).Append(", "); builder.Append(PublicKeyTokenField).Append("=").Append(string.IsNullOrWhiteSpace(PublicKeyToken) ? NullPublicKeyToken : PublicKeyToken.ToLower()); return(builder.ToString()); }
public void DotNetFrameworkFilterCheckPublicKeyToken(string publicKeyToken, bool succeed) { Assert.Equal(succeed, _assemblyFilter.IsFrameworkAssembly(string.Empty, PublicKeyToken.Parse(publicKeyToken))); }
private static bool IsKnownPublicKeyToken(PublicKeyToken publicKeyToken) => MicrosoftKeys.Contains(publicKeyToken);
public virtual bool IsFrameworkAssembly(string name, PublicKeyToken publicKeyToken) => IsKnownPublicKeyToken(publicKeyToken) || IsKnownName(name);
public virtual bool IsFrameworkMember(string name, PublicKeyToken publicKeyToken) => IsFrameworkAssembly(name, publicKeyToken);
private static bool IsKnownPublicKeyToken(PublicKeyToken publicKeyToken) { return(MicrosoftKeys.Contains(publicKeyToken)); }
public bool IsFrameworkAssembly(string name, PublicKeyToken publicKeyToken) => true;
/// <summary> /// Compares two <see cref="PublicKeyToken"/>s /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns>< 0 if a < b, 0 if a == b, > 0 if a > b</returns> public static int TokenCompareTo(PublicKeyToken a, PublicKeyToken b) { if (a == b) return 0; return TokenCompareTo(a == null ? null : a.Data, b == null ? null : b.Data); }
static IEnumerable <GacFileInfo> GetAssemblies(GacDirInfo gacInfo) { foreach (var subDir in gacInfo.SubDirs) { var baseDir = Path.Combine(gacInfo.Path, subDir); foreach (var dir in GetDirectories(baseDir)) { foreach (var dir2 in GetDirectories(dir)) { Version version; string culture; PublicKeyToken pkt; if (gacInfo.Version == 2) { var m = gac2Regex.Match(Path.GetFileName(dir2)); if (!m.Success || m.Groups.Count != 4) { continue; } if (!Version.TryParse(m.Groups[1].Value, out version)) { continue; } culture = m.Groups[2].Value; pkt = new PublicKeyToken(m.Groups[3].Value); if (PublicKeyBase.IsNullOrEmpty2(pkt)) { continue; } } else if (gacInfo.Version == 4) { var m = gac4Regex.Match(Path.GetFileName(dir2)); if (!m.Success || m.Groups.Count != 4) { continue; } if (!Version.TryParse(m.Groups[1].Value, out version)) { continue; } culture = m.Groups[2].Value; pkt = new PublicKeyToken(m.Groups[3].Value); if (PublicKeyBase.IsNullOrEmpty2(pkt)) { continue; } } else { throw new InvalidOperationException(); } var asmName = Path.GetFileName(dir); var file = Path.Combine(dir2, asmName) + ".dll"; if (!File.Exists(file)) { file = Path.Combine(dir2, asmName) + ".exe"; if (!File.Exists(file)) { continue; } } var asmInfo = new AssemblyNameInfo { Name = asmName, Version = version, Culture = culture, PublicKeyOrToken = pkt, }; yield return(new GacFileInfo(asmInfo, file)); } } } }
public static void EqualityTests() { var assemblyInfo1 = new AssemblyReferenceInformation("name", Version.Parse("4.0"), "neutral", PublicKeyToken.Parse("1234")); var assemblyInfo2 = new AssemblyReferenceInformation("Name", Version.Parse("4.0"), "neutral", PublicKeyToken.Parse("1234")); var assemblyInfo3 = new AssemblyReferenceInformation("name2", Version.Parse("4.0"), "neutral", PublicKeyToken.Parse("1234")); Assert.Equal($"name, Version=4.0, Culture=neutral, PublicKeyToken=1234", assemblyInfo1.ToString()); Assert.Equal($"Name, Version=4.0, Culture=neutral, PublicKeyToken=1234", assemblyInfo2.ToString()); Assert.Equal($"name2, Version=4.0, Culture=neutral, PublicKeyToken=1234", assemblyInfo3.ToString()); Assert.True(assemblyInfo1.Equals(assemblyInfo2)); Assert.False(assemblyInfo1.Equals(assemblyInfo3)); Assert.False(assemblyInfo2.Equals(assemblyInfo3)); Assert.Equal(assemblyInfo1.GetHashCode(), assemblyInfo2.GetHashCode()); Assert.NotEqual(assemblyInfo1.GetHashCode(), assemblyInfo3.GetHashCode()); Assert.NotEqual(assemblyInfo2.GetHashCode(), assemblyInfo3.GetHashCode()); }