Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SolutionPlatform.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.Generic;
5 using System.Collections.ObjectModel;
6 using System.Diagnostics;
7 using System.Linq;
8 using SiliconStudio.Core;
9 
10 namespace SiliconStudio.Assets
11 {
12  /// <summary>
13  /// Defines a solution platform.
14  /// </summary>
15  [DataContract("SolutionPlatform")]
17  {
18  /// <summary>
19  /// Initializes a new instance of the <see cref="SolutionPlatform"/> class.
20  /// </summary>
22  {
23  PlatformsPart = new SolutionPlatformPartCollection();
24  DefineConstants = new List<string>();
25  Properties = new PropertyCollection();
26  }
27 
28  /// <summary>
29  /// Gets the alternative names that will appear in the .sln file equivalent to this platform.
30  /// </summary>
31  /// <value>The alternative names.</value>
32  [DataMember(20)]
33  public SolutionPlatformPartCollection PlatformsPart { get; private set; }
34 
35  /// <summary>
36  /// Gets or sets the type of the platform.
37  /// </summary>
38  /// <value>The type.</value>
39  [DataMember(30)]
40  public PlatformType Type { get; set; }
41 
42  /// <summary>
43  /// Gets the define constants that will be used by the csproj of the platform.
44  /// </summary>
45  /// <value>The define constants.</value>
46  [DataMember(40)]
47  public List<string> DefineConstants { get; private set; }
48 
49  /// <summary>
50  /// Gets or sets a value indicating whether this <see cref="SolutionPlatform"/> is available on this machine.
51  /// </summary>
52  /// <value><c>true</c> if available; otherwise, <c>false</c>.</value>
53  [DataMember(50)]
54  public bool IsAvailable { get; set; }
55 
56  /// <summary>
57  /// Gets the dynamic properties associated with this profile.
58  /// </summary>
59  /// <value>The properties.</value>
60  [DataMember(60)]
61  public PropertyCollection Properties { get; private set; }
62 
63  /// <summary>
64  /// Gets the all <see cref="SolutionPlatformPart"/>.
65  /// </summary>
66  /// <returns>IEnumerable&lt;SolutionPlatformPart&gt;.</returns>
68  {
69  // Returns solution platform in alphabetical order
70  var parts = new List<SolutionPlatformPart>(1 + PlatformsPart.Count) { this };
71  parts.AddRange(PlatformsPart);
72 
73  return parts.OrderBy(part => part.SolutionName ?? part.Name, StringComparer.InvariantCultureIgnoreCase);
74  }
75 
77  {
78  if (part == null) throw new ArgumentNullException("part");
79  if (part.Configurations.Contains(configuration))
80  {
81  foreach (var property in part.Configurations[configuration].Properties)
82  {
83  yield return property;
84  }
85  }
86 
87  if (part.InheritConfigurations && !ReferenceEquals(part, this))
88  {
89  foreach (var property in Configurations[configuration].Properties)
90  {
91  yield return property;
92  }
93  }
94  }
95  }
96 
97  /// <summary>
98  /// Class SolutionAlternativePlatform.
99  /// </summary>
100  [DebuggerDisplay("Solution {Name} Configs [{Configurations.Count}]")]
101  public class SolutionPlatformPart
102  {
103  /// <summary>
104  /// Initializes a new instance of the <see cref="SolutionPlatformPart"/> class.
105  /// </summary>
107  {
108  UseWithExecutables = true;
109  UseWithLibraries = true;
110  IncludeInSolution = true;
111  Configurations = new SolutionConfigurationCollection { new SolutionConfiguration("Debug") { IsDebug = true }, new SolutionConfiguration("Release") };
112  }
113 
114  /// <summary>
115  /// Initializes a new instance of the <see cref="SolutionPlatformPart"/> class.
116  /// </summary>
117  /// <param name="name">The name.</param>
118  /// <exception cref="System.ArgumentNullException">name</exception>
119  public SolutionPlatformPart(string name) : this()
120  {
121  if (name == null) throw new ArgumentNullException("name");
122  Name = name;
123  }
124 
125  /// <summary>
126  /// Gets or sets the name of the alternative platform.
127  /// </summary>
128  /// <value>The name.</value>
129  public string Name { get; set; }
130 
131  /// <summary>
132  /// Gets or sets the solution name. If null, use the <see cref="Name"/>
133  /// </summary>
134  /// <value>The name.</value>
135  public string SolutionName { get; set; }
136 
137  /// <summary>
138  /// Gets or sets the display name. If null, use the <see cref="Name"/>.
139  /// </summary>
140  /// <value>
141  /// The display name.
142  /// </value>
143  public string DisplayName { get; set; }
144 
145  /// <summary>
146  /// Gets the name of the solution from <see cref="SolutionName"/>, using <see cref="Name"/> as a fallback.
147  /// </summary>
148  /// <value>The name of the safe solution.</value>
149  public string SafeSolutionName
150  {
151  get
152  {
153  return SolutionName ?? Name;
154  }
155  }
156 
157  /// <summary>
158  /// Gets or sets the CPU name, if this platform is CPU specific.
159  /// </summary>
160  /// <value>
161  /// The CPU name.
162  /// </value>
163  public string Cpu { get; set; }
164 
165  /// <summary>
166  /// Gets or sets the name of the alias. If != null, then this platform is only available in the solution and remapped
167  /// to the platform with this <see cref="Alias"/>
168  /// </summary>
169  /// <value>The name of the alias.</value>
170  public string Alias { get; set; }
171 
172  /// <summary>
173  /// Gets or sets a value indicating whether inherit configurations from parent <see cref="SolutionPlatform"/>
174  /// </summary>
175  /// <value><c>true</c> if [inherit configurations]; otherwise, <c>false</c>.</value>
176  public bool InheritConfigurations { get; set; }
177 
178  /// <summary>
179  /// Gets the configurations supported by this platform (by default contains 'Debug' and 'Release')
180  /// </summary>
181  public SolutionConfigurationCollection Configurations { get; private set; }
182 
183  public bool UseWithExecutables { get; set; }
184  public bool UseWithLibraries { get; set; }
185  public bool IncludeInSolution { get; set; }
186 
187  public string LibraryProjectName { get; set; }
188  public string ExecutableProjectName { get; set; }
189 
190  /// <summary>
191  /// Determines whether the project is handled by this platform.
192  /// </summary>
193  /// <param name="projectType">Type of the project.</param>
194  /// <returns><c>true</c> if the project is handled by this platform; otherwise, <c>false</c>.</returns>
195  public bool IsProjectHandled(ProjectType projectType)
196  {
197  return (projectType != ProjectType.Executable || UseWithExecutables) && (projectType != ProjectType.Library || UseWithLibraries);
198  }
199 
200  /// <summary>
201  /// Gets the name of the project configuration from <see cref="Alias"/>, with <see cref="SafeSolutionName"/> as a fallback.
202  /// </summary>
203  /// <value>The name of the safe solution.</value>
204  public string GetProjectName(ProjectType projectType)
205  {
206  switch (projectType)
207  {
208  case ProjectType.Executable:
209  return ExecutableProjectName ?? Alias ?? SafeSolutionName;
210  case ProjectType.Library:
211  return LibraryProjectName ?? Alias ?? SafeSolutionName;
212  default:
213  throw new ArgumentOutOfRangeException("projectType");
214  }
215  }
216  }
217 
218  /// <summary>
219  /// A collection of <see cref="SolutionPlatformPart"/>
220  /// </summary>
221  [DataContract("SolutionPlatformPartCollection")]
222  public class SolutionPlatformPartCollection : KeyedCollection<string, SolutionPlatformPart>
223  {
224  protected override string GetKeyForItem(SolutionPlatformPart item)
225  {
226  return item.Name;
227  }
228  }
229 
230  /// <summary>
231  /// A collection of <see cref="SolutionConfiguration"/>
232  /// </summary>
233  [DataContract("SolutionConfigurationCollection")]
234  public class SolutionConfigurationCollection : KeyedCollection<string, SolutionConfiguration>
235  {
236  protected override string GetKeyForItem(SolutionConfiguration item)
237  {
238  return item.Name;
239  }
240  }
241 
242  /// <summary>
243  /// A solution configuration used by <see cref="SolutionPlatform"/>
244  /// </summary>
245  [DataContract("SolutionConfiguration")]
246  [DebuggerDisplay("Config [{Name}]")]
248  {
249  /// <summary>
250  /// Initializes a new instance of the <see cref="SolutionConfiguration"/> class.
251  /// </summary>
252  public SolutionConfiguration(string name)
253  {
254  if (name == null) throw new ArgumentNullException("name");
255  Name = name;
256  Properties = new List<string>();
257  }
258 
259  /// <summary>
260  /// Gets or sets the configuration name (e.g. Debug, Release)
261  /// </summary>
262  /// <value>The name.</value>
263  public string Name { get; private set; }
264 
265  /// <summary>
266  /// Gets or sets a value indicating whether this instance is a debug configuration.
267  /// </summary>
268  /// <value><c>true</c> if this instance is debug; otherwise, <c>false</c>.</value>
269  public bool IsDebug { get; set; }
270 
271  /// <summary>
272  /// Gets the additional msbuild properties for a specific configuration (Debug or Release)
273  /// </summary>
274  /// <value>The msbuild configuration properties.</value>
275  public List<string> Properties { get; private set; }
276  }
277 }
Defines a solution platform.
A collection of SolutionConfiguration
SolutionConfiguration(string name)
Initializes a new instance of the SolutionConfiguration class.
PlatformType
Describes the platform operating system.
Definition: PlatformType.cs:9
SolutionConfigurationCollection Configurations
Gets the configurations supported by this platform (by default contains 'Debug' and 'Release') ...
Class SolutionAlternativePlatform.
string GetProjectName(ProjectType projectType)
Gets the name of the project configuration from Alias, with SafeSolutionName as a fallback...
IEnumerable< SolutionPlatformPart > GetParts()
Gets the all SolutionPlatformPart.
SolutionPlatformPart(string name)
Initializes a new instance of the SolutionPlatformPart class.
override string GetKeyForItem(SolutionConfiguration item)
SolutionPlatformPart()
Initializes a new instance of the SolutionPlatformPart class.
IEnumerable< string > GetConfigurationProperties(SolutionPlatformPart part, string configuration)
override string GetKeyForItem(SolutionPlatformPart item)
SolutionPlatform()
Initializes a new instance of the SolutionPlatform class.
ProjectType
Type of the project.
Definition: ProjectType.cs:11
bool InheritConfigurations
Gets or sets a value indicating whether inherit configurations from parent SolutionPlatform ...
A solution configuration used by SolutionPlatform
bool IsProjectHandled(ProjectType projectType)
Determines whether the project is handled by this platform.