4 using System.Collections;
5 using System.Collections.Generic;
6 using System.Collections.Specialized;
7 using System.Diagnostics;
9 using SiliconStudio.Core;
10 using SiliconStudio.Core.Diagnostics;
11 using SiliconStudio.Core.Extensions;
13 namespace SiliconStudio.Assets
19 [DebuggerDisplay(
"Count = {Count}")]
20 [DataContract(
"PackageCollection")]
23 private readonly List<Package> packages;
35 packages =
new List<Package>();
42 return packages.Count;
46 public bool IsReadOnly
56 return packages.GetEnumerator();
59 IEnumerator IEnumerable.GetEnumerator()
61 return GetEnumerator();
71 return packages.FirstOrDefault(
package => package.Id == packageGuid);
81 if (packageDependency == null)
throw new ArgumentNullException(
"packageDependency");
82 return Find(packageDependency.
Name, packageDependency.
Version);
93 if (name == null)
throw new ArgumentNullException(
"name");
94 if (versionRange == null)
throw new ArgumentNullException(
"versionRange");
95 var filter = versionRange.ToFilter();
96 return packages.FirstOrDefault(
package => package.Meta.Name == name && filter(package));
101 if (item == null)
throw new ArgumentNullException(
"item");
102 if (Find(item.
Id) == null)
105 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
111 var oldPackages =
new List<Package>(packages);
113 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, packages, oldPackages));
123 return packages.Any(
package => package.Id == packageGuid);
128 if (item == null)
throw new ArgumentNullException(
"item");
129 return ContainsById(item.
Id);
134 packages.CopyTo(array, arrayIndex);
139 var item = Find(packageGuid);
143 packages.Remove(item);
144 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item));
152 if (item == null)
throw new ArgumentNullException(
"item");
153 return RemoveById(item.
Id);
156 private void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
158 NotifyCollectionChangedEventHandler handler = CollectionChanged;
159 if (handler != null) handler(
this, e);
IEnumerator< Package > GetEnumerator()
Package Find(string name, PackageVersionRange versionRange)
Finds a package with the specified name and PackageVersionRange.
Package Find(Guid packageGuid)
Finds the specified package by its unique identifier.
Package Find(PackageDependency packageDependency)
Finds the a package already in this collection from the specified dependency.
bool ContainsById(Guid packageGuid)
Determines whether this collection contains a package with the specified package unique identifier...
string Name
Gets or sets the package name Id.
Guid Id
Gets or sets the unique identifier of this asset.
NotifyCollectionChangedEventHandler CollectionChanged
Occurs when the collection changes.
Use this class to provide a debug output in Visual Studio debugger.
bool Contains(Package item)
A reference to a package either internal (directly to a Package inside the same solution) or external...
void CopyTo(Package[] array, int arrayIndex)
bool Remove(Package item)
A package managing assets.
bool RemoveById(Guid packageGuid)
PackageVersionRange Version
Gets or sets the version.
PackageCollection()
Initializes a new instance of the PackageCollection class.
A dependency to a range of version.