Beispiel #1
0
        /// <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 (a is null || b is 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));
        }
Beispiel #2
0
 /// <summary>
 /// Gets the hash code of an assembly name
 /// </summary>
 /// <param name="a">Assembly name</param>
 /// <returns></returns>
 public int GetHashCode(IDmdAssemblyName?a)
 {
     if (a is null)
     {
         return(0);
     }
     return(StringComparer.OrdinalIgnoreCase.GetHashCode(a.Name ?? string.Empty));
 }
Beispiel #3
0
        IDmdAssemblyName FindAssemblyRef(DmdParsedTypeRef?nonNestedTypeRef)
        {
            IDmdAssemblyName?asmRef = null;

            if (!(nonNestedTypeRef is null))
            {
                asmRef = FindAssemblyRefCore(nonNestedTypeRef);
            }
            return(asmRef ?? ownerModule !.Assembly.GetName());
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
            public DmdTypeDef?GetTypeDef(IDmdAssemblyName?assemblyName, List <string> typeNames)
            {
                if (typeNames.Count == 0)
                {
                    return(null);
                }

                DmdAssemblyImpl?targetAssembly = assembly;

                if (assemblyName is not null && !assembly.AppDomainImpl.AssemblyNameEqualityComparer.Equals(targetAssembly.GetName(), assemblyName))
                {
                    targetAssembly = (DmdAssemblyImpl?)targetAssembly.AppDomain.GetAssembly(assemblyName);
                    if (targetAssembly is null)
                    {
                        return(null);
                    }
                }

                DmdTypeDef?type;

                DmdTypeUtilities.SplitFullName(typeNames[0], out var @namespace, out string name);

                var module = targetAssembly.ManifestModule;

                if (module is null)
                {
                    return(null);
                }
                var typeRef = new DmdParsedTypeRef(module, null, DmdTypeScope.Invalid, @namespace, name, null);

                type = targetAssembly.GetType(typeRef, ignoreCase);

                if (type is 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 (type is null)
                    {
                        return(null);
                    }
                }
                return(type);
            }