-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoenixContainerForms.cs
More file actions
75 lines (67 loc) · 2.08 KB
/
PhoenixContainerForms.cs
File metadata and controls
75 lines (67 loc) · 2.08 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections.Generic;
using Phoenix.Core;
using Phoenix.Helpers;
using Phoenix.Extentions;
namespace Phoenix
{
internal class PContainerFormsType : Dictionary<string, PhoenixForm> { }
public static class PContainer
{
private static PContainerFormsType _phoenixListForms = new PContainerFormsType();
internal static bool CheckExistsForm(string formName)
{
return _phoenixListForms.Has(formName).ToBool();
}
private static PhoenixException GetException(string formName)
{
return new PhoenixException(
$@"The container does not have a form with such a key - [{formName}]!",
new KeyNotFoundException()
);
}
/// <summary>
/// The method returns the form by its name.
/// </summary>
public static T Get<T>(string formName) where T : PhoenixForm
{
try
{
FormActivator.TryActivateForm<T>(formName);
return Converting.ToType<T>(_phoenixListForms.Get(formName));
}
catch (KeyNotFoundException)
{
throw GetException(formName);
}
}
/// <summary>
/// The method returns the form by its name.
/// </summary>
public static PhoenixForm Get(string formName)
{
try
{
FormActivator.TryActivateForm<PhoenixForm>(formName);
return _phoenixListForms.Get(formName);
}
catch (KeyNotFoundException)
{
throw GetException(formName);
}
}
/// <summary>
/// Adds the form to the list.
/// </summary>
public static void Append(string key, PhoenixForm form)
{
_phoenixListForms.Add(key, form);
}
/// <summary>
/// Removes the form from the list.
/// </summary>
public static void Delete(string key)
{
_phoenixListForms.Remove(key);
}
}
}