chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//            Copyright Keysight Technologies 2012-2019
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
using System.Xml.Serialization;
 
namespace OpenTap.Package
{
    /// <summary>
    /// Uniquely identifies a package in the OpenTAP package system.
    /// </summary>
    public class PackageIdentifier : IPackageIdentifier
    {
        /// <summary>
        /// Name of the package to which this object refers.
        /// </summary>
        [XmlAttribute]
        public string Name { get; set; }
 
        /// <summary>
        /// The Semantic Version compliant version of the package. 
        /// </summary>
        [XmlAttribute]
        public SemanticVersion Version { get; set; }
 
        /// <summary>
        /// CPU Architecture
        /// </summary>
        [XmlAttribute]
        public CpuArchitecture Architecture { get; set; }
 
        /// <summary>
        /// The operating system that this package supports
        /// </summary>
        [XmlAttribute]
        public string OS { get; set; }
 
        /// <summary>
        /// Creates a package identifier
        /// </summary>
        /// <param name="packageName">Name of the package.</param>
        /// <param name="version">Version of the package. This should be semver 2.0.0 compliant.</param>
        /// <param name="architecture">CPU architechture supported by the package.</param>
        /// <param name="os">Operating System supported by this package.</param>
        public PackageIdentifier(string packageName, string version, CpuArchitecture architecture, string os)
        {
            Name = packageName;
            if (version != null)
                Version = SemanticVersion.Parse(version);
            Architecture = architecture;
            OS = os;
        }
 
        /// <summary>
        /// Creates a package identifier
        /// </summary>
        /// <param name="packageName">Name of the package.</param>
        /// <param name="version">Version of the package.</param>
        /// <param name="architecture">CPU architechture supported by the package.</param>
        /// <param name="os">Operating System supported by this package.</param>
        public PackageIdentifier(string packageName, SemanticVersion version, CpuArchitecture architecture, string os)
        {
            Name = packageName;
            Version = version;
            Architecture = architecture;
            OS = os;
        }
 
        /// <summary>
        /// Creates a package identifier from another <see cref="IPackageIdentifier"/>
        /// </summary>
        public PackageIdentifier(IPackageIdentifier packageIdentifier) : this(packageIdentifier.Name, packageIdentifier.Version, packageIdentifier.Architecture, packageIdentifier.OS)
        {
            
        }
 
        internal PackageIdentifier()
        {
            
        }
        
        //override GetHashCode and Equals so PackageReference can be properly compared/distincted.
        /// <summary>
        /// Returns the hash code for this PackageIdentifier.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            int hash = 0;
            if (Name != null)
                hash ^= Name.GetHashCode();
            if (Version != null)
                hash ^= Version.GetHashCode();
            if (OS != null)
                hash ^= OS.GetHashCode();
            return hash ^ Architecture.GetHashCode();
        }
 
        /// <summary>
        /// Compare this PackageIdentifier to another object.
        /// </summary>
        public override bool Equals(object obj)
        {
            var other = obj as IPackageIdentifier;
            if (other == null) return false;
            return other.Name == Name && other.Version == Version && other.OS == OS && other.Architecture == Architecture;
        }
    }
}