Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PackageDependency.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.ObjectModel;
5 using System.ComponentModel;
6 using SiliconStudio.Core;
7 
8 namespace SiliconStudio.Assets
9 {
10  /// <summary>
11  /// A collection of <see cref="PackageProfile"/>.
12  /// </summary>
13  [DataContract("PackageDependencyCollection")]
14  public sealed class PackageDependencyCollection : KeyedCollection<string, PackageDependency>
15  {
16  protected override string GetKeyForItem(PackageDependency item)
17  {
18  return item.Name;
19  }
20  }
21 
22  /// <summary>
23  /// A reference to a package either internal (directly to a <see cref="Package"/> inside the same solution) or external
24  /// (to a package distributed on the store).
25  /// </summary>
26  [DataContract("PackageDependency")]
27  public sealed class PackageDependency : IEquatable<PackageDependency>
28  {
29  /// <summary>
30  /// Initializes a new instance of the <see cref="PackageDependency"/> class.
31  /// </summary>
33  {
34  }
35 
36  /// <summary>
37  /// Initializes a new instance of the <see cref="PackageDependency"/> class.
38  /// </summary>
39  /// <param name="name">The name.</param>
40  /// <param name="version">The version.</param>
41  public PackageDependency(string name, PackageVersionRange version)
42  {
43  Name = name;
44  Version = version;
45  }
46 
47  /// <summary>
48  /// Gets or sets the package name Id.
49  /// </summary>
50  /// <value>The name.</value>
51  [DefaultValue(null)]
52  [DataMember(10)]
53  public string Name { get; set; }
54 
55  /// <summary>
56  /// Gets or sets the version.
57  /// </summary>
58  /// <value>The version.</value>
59  [DefaultValue(null)]
60  [DataMember(20)]
61  public PackageVersionRange Version { get; set; }
62 
63  /// <summary>
64  /// Clones this instance.
65  /// </summary>
66  /// <returns>PackageDependency.</returns>
68  {
69  return new PackageDependency(Name, Version);
70  }
71 
72  public bool Equals(PackageDependency other)
73  {
74  if (ReferenceEquals(null, other)) return false;
75  if (ReferenceEquals(this, other)) return true;
76  return string.Equals(Name, other.Name) && Equals(Version, other.Version);
77  }
78 
79  public override bool Equals(object obj)
80  {
81  if (ReferenceEquals(null, obj)) return false;
82  if (ReferenceEquals(this, obj)) return true;
83  return obj is PackageDependency && Equals((PackageDependency)obj);
84  }
85 
86  public override int GetHashCode()
87  {
88  unchecked
89  {
90  return ((Name != null ? Name.GetHashCode() : 0)*397) ^ (Version != null ? Version.GetHashCode() : 0);
91  }
92  }
93 
94  public static bool operator ==(PackageDependency left, PackageDependency right)
95  {
96  return Equals(left, right);
97  }
98 
99  public static bool operator !=(PackageDependency left, PackageDependency right)
100  {
101  return !Equals(left, right);
102  }
103 
104  /// <inherit/>
105  public override string ToString()
106  {
107  if (Name != null)
108  {
109  return string.Format("{0} {1}", Name, Version);
110  }
111  return "Empty";
112  }
113  }
114 }
override string GetKeyForItem(PackageDependency item)
PackageDependency(string name, PackageVersionRange version)
Initializes a new instance of the PackageDependency class.
PackageDependency Clone()
Clones this instance.
A reference to a package either internal (directly to a Package inside the same solution) or external...
PackageDependency()
Initializes a new instance of the PackageDependency class.
PackageVersionRange Version
Gets or sets the version.
A dependency to a range of version.
bool Equals(PackageDependency other)