-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPlugin.cs
48 lines (44 loc) · 1.58 KB
/
Plugin.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using JetBrains.Annotations;
using NFive.SDK.Plugins.Configuration;
namespace NFive.SDK.Plugins
{
/// <summary>
/// Represents a loaded NFive plugin configuration including nested dependencies.
/// </summary>
/// <seealso cref="Core.Plugins.Plugin" />
[PublicAPI]
public class Plugin : Core.Plugins.Plugin
{
/// <summary>
/// Gets or sets the dependency plugins.
/// </summary>
/// <value>
/// The dependency plugins.
/// </value>
public List<Plugin> DependencyNodes { get; set; }
/// <summary>
/// Loads a <see cref="Plugin" /> from the specified definition file.
/// </summary>
/// <param name="path">The path to the plugin definition file.</param>
/// <returns>The loaded <see cref="Plugin" />.</returns>
/// <exception cref="ArgumentNullException">path - A valid file path must be specified.</exception>
/// <exception cref="FileNotFoundException">Unable to find the plugin definition file.</exception>
public static Plugin Load(string path)
{
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullException(nameof(path), "A valid file path must be specified.");
if (!File.Exists(path)) throw new FileNotFoundException("Unable to find the plugin definition file.", path);
return Yaml.Deserialize<Plugin>(File.ReadAllText(path));
}
/// <summary>
/// Serialize this instance and saves the to the specified path.
/// </summary>
/// <param name="path">The path to save the file at.</param>
public void Save(string path)
{
File.WriteAllText(path, Yaml.Serialize(this));
}
}
}