forked from dotnet/try
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.cs
More file actions
53 lines (41 loc) · 1.57 KB
/
Project.cs
File metadata and controls
53 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Microsoft.DotNet.Try.Protocol.ClientApi
{
[JsonConverter(typeof(ProjectJsonConverter))]
public class Project : FeatureContainer
{
public string ProjectTemplate { get; }
public SourceFile[] Files { get; }
public Project(string projectTemplate, IEnumerable<SourceFile> files)
{
if (string.IsNullOrWhiteSpace(projectTemplate))
{
throw new ArgumentException("Value cannot be null or whitespace.", nameof(projectTemplate));
}
if (files == null)
{
throw new ArgumentNullException(nameof(files));
}
Files = files.Where(f => f != null).ToArray();
if (Files.Length == 0)
{
throw new ArgumentException("Collection cannot be empty.", nameof(files));
}
ProjectTemplate = projectTemplate;
}
private class ProjectJsonConverter : FeatureContainerConverter<Project>
{
protected override void AddProperties(Project container, JObject o)
{
o.Add(new JProperty("projectTemplate", container.ProjectTemplate));
o.Add(new JProperty("files", JArray.FromObject(container.Files)));
}
}
}
}