コード例 #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 ((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));
        }
コード例 #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 ((object)a == null)
     {
         return(0);
     }
     return(StringComparer.OrdinalIgnoreCase.GetHashCode(a.Name ?? string.Empty));
 }
コード例 #3
0
ファイル: DmdTypeNameParser.cs プロジェクト: zz110/dnSpy
        IDmdAssemblyName FindAssemblyRef(DmdParsedTypeRef nonNestedTypeRef)
        {
            IDmdAssemblyName asmRef = null;

            if ((object)nonNestedTypeRef != null)
            {
                asmRef = FindAssemblyRefCore(nonNestedTypeRef);
            }
            return(asmRef ?? ownerModule.Assembly.GetName());
        }
コード例 #4
0
ファイル: DmdTypeNameParser.cs プロジェクト: zz110/dnSpy
        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);
        }
コード例 #5
0
            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);
            }
コード例 #6
0
 /// <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;
 }
コード例 #7
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 ((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()));
        }
コード例 #8
0
ファイル: IDmdAssemblyName.cs プロジェクト: haise0/dnSurgeon
 public static void FormatFullNameTo(this IDmdAssemblyName self, StringBuilder sb) =>
 DmdAssemblyNameFormatter.Format(sb, self.Name, self.Version, self.CultureName, self.GetPublicKeyToken(), self.RawFlags, isPublicKeyToken: true);
コード例 #9
0
ファイル: DmdAppDomain.cs プロジェクト: wagnerhsu/tools-dnSpy
 /// <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);
コード例 #10
0
ファイル: DmdAppDomain.cs プロジェクト: wagnerhsu/tools-dnSpy
 /// <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);
コード例 #11
0
ファイル: DmdTypeScope.cs プロジェクト: haise0/dnSurgeon
 /// <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;
 }
コード例 #12
0
ファイル: DmdTypeScope.cs プロジェクト: haise0/dnSurgeon
 /// <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));
 }