コード例 #1
0
ファイル: AssemblyNameExtension.cs プロジェクト: 3F/IeXod
        /// <summary>
        /// Compare one assembly name to another.
        /// </summary>
        /// <param name="that"></param>
        /// <returns></returns>
        internal int CompareTo(AssemblyNameExtension that)
        {
            // Are they identical?
            if (this.Equals(that))
            {
                return(0);
            }

            // Are the base names not identical?
            int result = CompareBaseNameTo(that);

            if (result != 0)
            {
                return(result);
            }

            // We need some collating order for these, alphabetical by FullName seems as good as any.
            return(String.Compare(this.FullName, that.FullName, StringComparison.OrdinalIgnoreCase));
        }
コード例 #2
0
ファイル: AssemblyNameExtension.cs プロジェクト: 3F/IeXod
        /// <summary>
        /// Compare two base names as quickly as possible.
        /// </summary>
        /// <param name="that"></param>
        /// <returns></returns>
        internal int CompareBaseNameTo(AssemblyNameExtension that)
        {
            int result = CompareBaseNameToImpl(that);

#if DEBUG
            // Now, compare to the real value to make sure the result was accurate.
            AssemblyName a1 = this.asAssemblyName;
            AssemblyName a2 = that.asAssemblyName;
            if (a1 == null)
            {
                a1 = new AssemblyName(this.asString);
            }
            if (a2 == null)
            {
                a2 = new AssemblyName(that.asString);
            }

            int baselineResult = String.Compare(a1.Name, a2.Name, StringComparison.OrdinalIgnoreCase);
            Debug.Assert(result == baselineResult, "Optimized version of CompareBaseNameTo didn't return the same result as the baseline.");
#endif
            return(result);
        }
コード例 #3
0
ファイル: AssemblyNameExtension.cs プロジェクト: 3F/IeXod
        /// <summary>
        /// Compare two assembly names for equality.
        /// </summary>
        /// <param name="that"></param>
        /// <returns></returns>
        internal bool Equals(AssemblyNameExtension that)
        {
            // Pointer compare.
            if (this == that)
            {
                return(true);
            }

            // Do both have assembly names?
            if (this.asAssemblyName != null && that.asAssemblyName != null)
            {
                // Pointer compare.
                if (this.asAssemblyName == that.asAssemblyName)
                {
                    return(true);
                }
            }

            // Do both have strings that equal each-other?
            if (this.asString != null && that.asString != null)
            {
                if (this.asString == that.asString)
                {
                    return(true);
                }

                // If they weren't identical then they might still differ only by
                // case. So we can't assume that they don't match. So fall through...
            }

            // Do the names match?
            if (0 != String.Compare(Name, that.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Do the versions match?
            if (Version != that.Version)
            {
                return(false);
            }

            // Do the Cultures match?
            CultureInfo aCulture = CultureInfo;
            CultureInfo bCulture = that.CultureInfo;

            if (aCulture == null)
            {
                aCulture = CultureInfo.InvariantCulture;
            }
            if (bCulture == null)
            {
                bCulture = CultureInfo.InvariantCulture;
            }
            if (aCulture.LCID != bCulture.LCID)
            {
                return(false);
            }

            // Do the PKTs match?
            byte[] aPKT = GetPublicKeyToken();
            byte[] bPKT = that.GetPublicKeyToken();

            // Some assemblies (real case was interop assembly) may have null PKTs.
            if (aPKT == null)
            {
                aPKT = new byte[0];
            }
            if (bPKT == null)
            {
                bPKT = new byte[0];
            }

            if (aPKT.Length != bPKT.Length)
            {
                return(false);
            }
            for (int i = 0; i < aPKT.Length; ++i)
            {
                if (aPKT[i] != bPKT[i])
                {
                    return(false);
                }
            }

            return(true);
        }