2 // System.ApplicationId class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Runtime.InteropServices;
36 public sealed class ApplicationId {
38 private byte[] _token;
40 private Version _version;
42 private string _culture;
44 public ApplicationId (byte[] publicKeyToken, string name, Version version, string processorArchitecture, string culture)
46 if (publicKeyToken == null)
47 throw new ArgumentNullException ("publicKeyToken");
49 throw new ArgumentNullException ("name");
51 throw new ArgumentNullException ("version");
53 _token = (byte[]) publicKeyToken.Clone ();
56 _proc = processorArchitecture;
62 public string Culture {
63 get { return _culture; }
70 public string ProcessorArchitecture {
74 public byte[] PublicKeyToken {
75 get { return (byte[]) _token.Clone (); }
78 public Version Version {
79 get { return _version; }
84 public ApplicationId Copy ()
86 return new ApplicationId (_token, _name, _version, _proc, _culture);
89 public override bool Equals (object o)
93 ApplicationId appid = (o as ApplicationId);
96 if (_name != appid._name)
98 if (_proc != appid._proc)
100 if (_culture != appid._culture)
102 if (!_version.Equals (appid._version))
104 if (_token.Length != appid._token.Length)
106 for (int i=0; i < _token.Length; i++)
107 if (_token [i] != appid._token [i])
112 public override int GetHashCode ()
114 int code = _name.GetHashCode () ^ _version.GetHashCode ();
115 for (int i=0; i < _token.Length; i++)
117 // ProcessorArchitecture and Culture aren't part of the hash code
118 // Confirmed by Microsoft in FDBK13339
122 public override string ToString ()
124 StringBuilder sb = new StringBuilder ();
126 if (_culture != null)
127 sb.AppendFormat (", culture=\"{0}\"", _culture);
128 sb.AppendFormat (", version=\"{0}\", publicKeyToken=\"", _version);
129 for (int i=0; i < _token.Length; i++)
130 sb.Append (_token [i].ToString ("X2"));
132 sb.AppendFormat ("\", processorArchitecture =\"{0}\"", _proc);
135 return sb.ToString ();