Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ProjectCollection.cs
Go to the documentation of this file.
1 #region License
2 
3 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
4 // This file is distributed under MIT License. See LICENSE.md for details.
5 //
6 // SLNTools
7 // Copyright (c) 2009
8 // by Christian Warren
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
13 // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
16 // of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23 
24 #endregion
25 
26 using System;
27 using System.Collections.Generic;
28 using System.Collections.ObjectModel;
29 using System.Diagnostics;
30 using System.Linq;
31 
32 namespace SiliconStudio.Core.VisualStudio
33 {
34  /// <summary>
35  /// A collection of <see cref="Project"/>
36  /// </summary>
37  [DebuggerDisplay("Count = {Count}")]
38  public sealed class ProjectCollection : KeyedCollection<Guid, Project>
39  {
40  private readonly Solution solution;
41 
42  /// <summary>
43  /// Initializes a new instance of the <see cref="ProjectCollection"/> class.
44  /// </summary>
45  /// <param name="container">The container.</param>
46  /// <exception cref="System.ArgumentNullException">container</exception>
47  internal ProjectCollection(Solution container)
48  {
49  if (container == null)
50  throw new ArgumentNullException("container");
51 
52  solution = container;
53  }
54 
55  /// <summary>
56  /// Initializes a new instance of the <see cref="ProjectCollection"/> class.
57  /// </summary>
58  /// <param name="container">The container.</param>
59  /// <param name="items">The items.</param>
60  internal ProjectCollection(Solution container, IEnumerable<Project> items)
61  : this(container)
62  {
63  this.AddRange(items);
64  }
65 
66  /// <summary>
67  /// Gets the solution this project is attached to.
68  /// </summary>
69  /// <value>The solution.</value>
70  public Solution Solution
71  {
72  get
73  {
74  return solution;
75  }
76  }
77 
78  /// <summary>
79  /// Finds a project by its full name.
80  /// </summary>
81  /// <param name="projectFullName">Full name of the project.</param>
82  /// <returns>The Project or null if not found.</returns>
83  public Project FindByFullName(string projectFullName)
84  {
85  return this.FirstOrDefault(item => string.Compare(item.FullName, projectFullName, StringComparison.InvariantCultureIgnoreCase) == 0);
86  }
87 
88  /// <summary>
89  /// Finds a project by its unique identifier.
90  /// </summary>
91  /// <param name="guid">The unique identifier.</param>
92  /// <returns>The project or null if not found.</returns>
93  public Project FindByGuid(Guid guid)
94  {
95  return (Contains(guid)) ? this[guid] : null;
96  }
97 
98  /// <summary>
99  /// Sorts this instance.
100  /// </summary>
101  public void Sort()
102  {
103  Sort((p1, p2) => StringComparer.InvariantCultureIgnoreCase.Compare(p1.FullName, p2.FullName));
104  }
105 
106  public void Sort(Comparison<Project> comparer)
107  {
108  var tempList = new List<Project>(this);
109  tempList.Sort(comparer);
110 
111  Clear();
112  this.AddRange(tempList);
113  }
114 
115  protected override Guid GetKeyForItem(Project item)
116  {
117  return item.Guid;
118  }
119 
120  protected override void InsertItem(int index, Project item)
121  {
122  // Add a clone of the item instead of the item itself
123  base.InsertItem(index, new Project(solution, item));
124  }
125 
126  protected override void SetItem(int index, Project item)
127  {
128  // Add a clone of the item instead of the item itself
129  base.SetItem(index, new Project(solution, item));
130  }
131  }
132 }
A project referenced by a VisualStudio solution.
Definition: Project.cs:35
override void InsertItem(int index, Project item)
A VisualStudio solution.
Definition: Solution.cs:37
EnvDTE.Project Project
Project FindByFullName(string projectFullName)
Finds a project by its full name.
override void SetItem(int index, Project item)
void Sort(Comparison< Project > comparer)
Project FindByGuid(Guid guid)
Finds a project by its unique identifier.