Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AssetFolderCollection.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;
5 using System.Collections.Generic;
6 using System.Diagnostics;
7 using System.Linq;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Diagnostics;
10 using SiliconStudio.Core.IO;
11 
12 namespace SiliconStudio.Assets
13 {
14  /// <summary>
15  /// A collection of <see cref="AssetFolder"/>
16  /// </summary>
17  [DataContract("AssetFolderCollection")]
18  [DebuggerTypeProxy(typeof(CollectionDebugView))]
19  [DebuggerDisplay("Count = {Count}")]
20  public sealed class AssetFolderCollection : ICollection<AssetFolder>
21  {
22  private readonly List<AssetFolder> folders;
23 
24  /// <summary>
25  /// Initializes a new instance of the <see cref="AssetFolderCollection"/> class.
26  /// </summary>
28  {
29  folders = new List<AssetFolder>();
30  }
31 
32  /// <inheritdoc/>
33  public void Add(AssetFolder item)
34  {
35  if (item == null) throw new ArgumentNullException("item");
36  if (item.Path == null)
37  {
38  throw new ArgumentOutOfRangeException("item", "SourceFolder.Folder cannot be null");
39  }
40 
41  // If a folder is already added, use it and squash the item to add to the existing folder.
42  var existingFolder = Find(item.Path);
43  if (existingFolder != null)
44  {
45  existingFolder.RawImports.AddRange(item.RawImports);
46  }
47  else
48  {
49  folders.Add(item);
50  }
51  }
52 
53  public AssetFolder Find(UDirectory folder)
54  {
55  return folders.FirstOrDefault(sourceFolder => sourceFolder.Path == folder);
56  }
57 
58  /// <inheritdoc/>
59  public void Clear()
60  {
61  folders.Clear();
62  }
63 
64  /// <inheritdoc/>
65  public bool Contains(AssetFolder item)
66  {
67  if (item == null) throw new ArgumentNullException("item");
68  return folders.Contains(item);
69  }
70 
71  /// <inheritdoc/>
72  public void CopyTo(AssetFolder[] array, int arrayIndex)
73  {
74  folders.CopyTo(array, arrayIndex);
75  }
76 
77  /// <summary>
78  /// Clones this instance to the specified instance.
79  /// </summary>
80  /// <param name="foldersTo">The folders.</param>
81  /// <exception cref="System.ArgumentNullException">folders</exception>
82  public void CloneTo(AssetFolderCollection foldersTo)
83  {
84  if (foldersTo == null) throw new ArgumentNullException("folders");
85  foreach (var sourceFolder in this)
86  {
87  foldersTo.Add(sourceFolder.Clone());
88  }
89  }
90 
91  /// <inheritdoc/>
92  public bool Remove(AssetFolder item)
93  {
94  if (item == null) throw new ArgumentNullException("item");
95  return folders.Remove(item);
96  }
97 
98  /// <inheritdoc/>
99  public int Count
100  {
101  get
102  {
103  return folders.Count;
104  }
105  }
106 
107  /// <inheritdoc/>
108  bool ICollection<AssetFolder>.IsReadOnly
109  {
110  get
111  {
112  return false;
113  }
114  }
115 
116  /// <inheritdoc/>
117  public IEnumerator<AssetFolder> GetEnumerator()
118  {
119  return folders.GetEnumerator();
120  }
121 
122  /// <inheritdoc/>
123  IEnumerator IEnumerable.GetEnumerator()
124  {
125  return ((IEnumerable)folders).GetEnumerator();
126  }
127  }
128 }
A location relative to a package from where assets will be loaded
Definition: AssetFolder.cs:16
AssetFolderCollection()
Initializes a new instance of the AssetFolderCollection class.
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
Definition: UDirectory.cs:13
void CopyTo(AssetFolder[] array, int arrayIndex)
void CloneTo(AssetFolderCollection foldersTo)
Clones this instance to the specified instance.
UDirectory Path
Gets or sets the folder.
Definition: AssetFolder.cs:44
Use this class to provide a debug output in Visual Studio debugger.