The Labs \ Source Viewer \ SSCLI \ System \ ApplicationId

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. //
  16. // ApplicationId.cs
  17. //
  18. // This class identifies a deployment or manifest identity.
  19. //
  20. namespace System
  21. {
  22.     using System.Reflection;
  23.     using System.Security;
  24.     using System.Security.Policy;
  25.     using System.Security.Util;
  26.     using System.Text;
  27.    
  28.     [Serializable()]
  29.     [System.Runtime.InteropServices.ComVisible(true)]
  30.     public sealed class ApplicationId
  31.     {
  32.         private string m_name;
  33.         private Version m_version;
  34.         private string m_processorArchitecture;
  35.         private string m_culture;
  36.         internal byte[] m_publicKeyToken;
  37.        
  38.         internal ApplicationId()
  39.         {
  40.         }
  41.        
  42.         //
  43.         // Public.
  44.         //
  45.        
  46.         public ApplicationId(byte[] publicKeyToken, string name, Version version, string processorArchitecture, string culture)
  47.         {
  48.             if (name == null)
  49.                 throw new ArgumentNullException("name");
  50.             if (name.Length == 0)
  51.                 throw new ArgumentException(Environment.GetResourceString("Argument_EmptyApplicationName"));
  52.             if (version == null)
  53.                 throw new ArgumentNullException("version");
  54.             if (publicKeyToken == null)
  55.                 throw new ArgumentNullException("publicKeyToken");
  56.            
  57.             m_publicKeyToken = new byte[publicKeyToken.Length];
  58.             Array.Copy(publicKeyToken, 0, m_publicKeyToken, 0, publicKeyToken.Length);
  59.             m_name = name;
  60.             m_version = version;
  61.             m_processorArchitecture = processorArchitecture;
  62.             m_culture = culture;
  63.         }
  64.        
  65.         public byte[] PublicKeyToken {
  66.             get {
  67.                 byte[] publicKeyToken = new byte[m_publicKeyToken.Length];
  68.                 Array.Copy(m_publicKeyToken, 0, publicKeyToken, 0, m_publicKeyToken.Length);
  69.                 return publicKeyToken;
  70.             }
  71.         }
  72.        
  73.         public string Name {
  74.             get { return m_name; }
  75.         }
  76.        
  77.         public Version Version {
  78.             get { return m_version; }
  79.         }
  80.        
  81.         public string ProcessorArchitecture {
  82.             get { return m_processorArchitecture; }
  83.         }
  84.        
  85.         public string Culture {
  86.             get { return m_culture; }
  87.         }
  88.        
  89.         public ApplicationId Copy()
  90.         {
  91.             return new ApplicationId(m_publicKeyToken, m_name, m_version, m_processorArchitecture, m_culture);
  92.         }
  93.        
  94.         public override string ToString()
  95.         {
  96.             StringBuilder sb = new StringBuilder();
  97.             sb.Append(this.m_name);
  98.             if (m_culture != null) {
  99.                 sb.Append(", culture=\"");
  100.                 sb.Append(m_culture);
  101.                 sb.Append("\"");
  102.             }
  103.             sb.Append(", version=\"");
  104.             sb.Append(m_version.ToString());
  105.             sb.Append("\"");
  106.             if (m_publicKeyToken != null) {
  107.                 sb.Append(", publicKeyToken=\"");
  108.                 sb.Append(Hex.EncodeHexString(m_publicKeyToken));
  109.                 sb.Append("\"");
  110.             }
  111.             if (m_processorArchitecture != null) {
  112.                 sb.Append(", processorArchitecture =\"");
  113.                 sb.Append(this.m_processorArchitecture);
  114.                 sb.Append("\"");
  115.             }
  116.             return sb.ToString();
  117.         }
  118.        
  119.         public override bool Equals(object o)
  120.         {
  121.             ApplicationId other = (o as ApplicationId);
  122.             if (other == null)
  123.                 return false;
  124.            
  125.             if (!(Equals(this.m_name, other.m_name) && Equals(this.m_version, other.m_version) && Equals(this.m_processorArchitecture, other.m_processorArchitecture) && Equals(this.m_culture, other.m_culture)))
  126.                 return false;
  127.            
  128.             if (this.m_publicKeyToken.Length != other.m_publicKeyToken.Length)
  129.                 return false;
  130.            
  131.             for (int i = 0; i < this.m_publicKeyToken.Length; ++i) {
  132.                 if (this.m_publicKeyToken[i] != other.m_publicKeyToken[i])
  133.                     return false;
  134.             }
  135.            
  136.             return true;
  137.         }
  138.        
  139.         public override int GetHashCode()
  140.         {
  141.             // Note: purposely skipping publicKeyToken, processor architecture and culture as they
  142.             // are less likely to make things not equal than name and version.
  143.             return m_name.GetHashCode() ^ m_version.GetHashCode();
  144.         }
  145.     }
  146. }

Developer Fusion