/// <summary> /// Compares two assembly names /// </summary> /// <param name="a">First assembly name</param> /// <param name="b">Second assembly name</param> /// <returns></returns> public bool Equals(IDmdAssemblyName a, IDmdAssemblyName b) { if ((object)a == b) { return(true); } if ((object)a == null || (object)b == null) { return(false); } // We do not compare the version number. The runtime can redirect an assembly // reference from a requested version to any other version. // The public key token is also ignored. Only .NET Framwork checks it (.NET Core // and Unity ignore it). We could add a new option to ignore the PKT but it would // require too many changes to the code (they access singleton comparers) and isn't // worth it. It's also being replaced by .NET Core. It's not common for two // assemblies loaded in the same process to have the same assembly name but a // different public key token. const DmdAssemblyNameFlags flagsMask = DmdAssemblyNameFlags.ContentType_Mask; return((a.RawFlags & flagsMask) == (b.RawFlags & flagsMask) && StringComparer.OrdinalIgnoreCase.Equals(a.Name, b.Name) && StringComparer.OrdinalIgnoreCase.Equals(a.CultureName ?? string.Empty, b.CultureName ?? string.Empty)); }
/// <summary> /// Gets the hash code of an assembly name /// </summary> /// <param name="a">Assembly name</param> /// <returns></returns> public int GetHashCode(IDmdAssemblyName a) { if ((object)a == null) { return(0); } return(StringComparer.OrdinalIgnoreCase.GetHashCode(a.Name ?? string.Empty)); }
IDmdAssemblyName FindAssemblyRef(DmdParsedTypeRef nonNestedTypeRef) { IDmdAssemblyName asmRef = null; if ((object)nonNestedTypeRef != null) { asmRef = FindAssemblyRefCore(nonNestedTypeRef); } return(asmRef ?? ownerModule.Assembly.GetName()); }
DmdType Resolve(IDmdAssemblyName asmRef, DmdType typeRef) { var asm = ownerModule.Assembly; var asmName = asm.GetName(); if (!DmdMemberInfoEqualityComparer.DefaultOther.Equals(asmRef, asmName)) { return(null); } var td = typeRef.ResolveNoThrow(); return(td?.Module == ownerModule ? td : null); }
public DmdTypeDef GetTypeDef(IDmdAssemblyName assemblyName, List <string> typeNames) { if (typeNames.Count == 0) { return(null); } var targetAssembly = assembly; if (assemblyName != null && !AssemblyNameEqualityComparer.Instance.Equals(targetAssembly.GetName(), assemblyName)) { targetAssembly = (DmdAssemblyImpl)targetAssembly.AppDomain.GetAssembly(assemblyName); if (targetAssembly == null) { return(null); } } DmdTypeDef type; DmdTypeUtilities.SplitFullName(typeNames[0], out string @namespace, out string name); var module = targetAssembly.ManifestModule; if (module == null) { return(null); } var typeRef = new DmdParsedTypeRef(module, null, DmdTypeScope.Invalid, @namespace, name, null); type = targetAssembly.GetType(typeRef, ignoreCase); if ((object)type == null) { return(null); } for (int i = 1; i < typeNames.Count; i++) { var flags = DmdBindingFlags.Public | DmdBindingFlags.NonPublic; if (ignoreCase) { flags |= DmdBindingFlags.IgnoreCase; } type = (DmdTypeDef)type.GetNestedType(typeNames[i], flags); if ((object)type == null) { return(null); } } return(type); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Assembly name</param> public DmdReadOnlyAssemblyName(IDmdAssemblyName name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name.Name; Version = name.Version; CultureName = name.CultureName; RawFlags = name.RawFlags; publicKey = DmdAssemblyName.CloneArray(name.GetPublicKey()); publicKeyToken = DmdAssemblyName.CloneArray(name.GetPublicKeyToken()); HashAlgorithm = name.HashAlgorithm; }
/// <summary> /// Compares two assembly names /// </summary> /// <param name="a">First assembly name</param> /// <param name="b">Second assembly name</param> /// <returns></returns> public bool Equals(IDmdAssemblyName a, IDmdAssemblyName b) { if ((object)a == b) { return(true); } if ((object)a == null || (object)b == null) { return(false); } // We do not compare the version number. The runtime can redirect an assembly // reference from a requested version to any other version. const DmdAssemblyNameFlags flagsMask = DmdAssemblyNameFlags.ContentType_Mask; return((a.RawFlags & flagsMask) == (b.RawFlags & flagsMask) && StringComparer.OrdinalIgnoreCase.Equals(a.Name, b.Name) && StringComparer.OrdinalIgnoreCase.Equals(a.CultureName ?? string.Empty, b.CultureName ?? string.Empty) && Impl.AssemblyNameEqualityComparer.PublicKeyTokenEquals(a.GetPublicKeyToken(), b.GetPublicKeyToken())); }
public static void FormatFullNameTo(this IDmdAssemblyName self, StringBuilder sb) => DmdAssemblyNameFormatter.Format(sb, self.Name, self.Version, self.CultureName, self.GetPublicKeyToken(), self.RawFlags, isPublicKeyToken: true);
/// <summary> /// Loads an assembly /// </summary> /// <param name="context">Evaluation context</param> /// <param name="name">Assembly name</param> /// <returns></returns> public abstract DmdAssembly Load(object context, IDmdAssemblyName name);
/// <summary> /// Gets an assembly or returns null if there's no such assembly /// </summary> /// <param name="name">Assembly name</param> /// <returns></returns> public abstract DmdAssembly GetAssembly(IDmdAssemblyName name);
/// <summary> /// Constructor /// </summary> /// <param name="assemblyRef">Assembly reference</param> public DmdTypeScope(IDmdAssemblyName assemblyRef) { Kind = DmdTypeScopeKind.AssemblyRef; Data = assemblyRef ?? throw new ArgumentNullException(nameof(assemblyRef)); Data2 = null; }
/// <summary> /// Constructor /// </summary> /// <param name="assembly">Assembly</param> /// <param name="moduleName">Module name</param> public DmdTypeScope(IDmdAssemblyName assembly, string moduleName) { Kind = DmdTypeScopeKind.ModuleRef; Data = moduleName ?? throw new ArgumentNullException(nameof(moduleName)); Data2 = assembly ?? throw new ArgumentNullException(nameof(assembly)); }