Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NestedContainer.cs
Go to the documentation of this file.
2
4
6{
7 private sealed class Site : INestedSite, ISite, IServiceProvider
8 {
9 private string _name;
10
11 public IComponent Component { get; }
12
13 public IContainer Container { get; }
14
15 public bool DesignMode
16 {
17 get
18 {
19 IComponent owner = ((NestedContainer)Container).Owner;
20 if (owner != null && owner.Site != null)
21 {
22 return owner.Site.DesignMode;
23 }
24 return false;
25 }
26 }
27
28 public string FullName
29 {
30 get
31 {
32 if (_name != null)
33 {
34 string ownerName = ((NestedContainer)Container).OwnerName;
35 string text = _name;
36 if (ownerName != null)
37 {
38 text = ownerName + "." + text;
39 }
40 return text;
41 }
42 return _name;
43 }
44 }
45
46 public string Name
47 {
48 get
49 {
50 return _name;
51 }
52 [RequiresUnreferencedCode("The Type of components in the container cannot be statically discovered to validate the name.")]
53 set
54 {
55 if (value == null || _name == null || !value.Equals(_name))
56 {
57 ((NestedContainer)Container).ValidateName(Component, value);
58 _name = value;
59 }
60 }
61 }
62
63 internal Site(IComponent component, NestedContainer container, string name)
64 {
65 Component = component;
66 Container = container;
67 _name = name;
68 }
69
70 public object GetService(Type service)
71 {
72 if (!(service == typeof(ISite)))
73 {
74 return ((NestedContainer)Container).GetService(service);
75 }
76 return this;
77 }
78 }
79
80 public IComponent Owner { get; }
81
82 protected virtual string? OwnerName
83 {
84 get
85 {
86 string result = null;
87 if (Owner != null && Owner.Site != null)
88 {
89 result = ((!(Owner.Site is INestedSite nestedSite)) ? Owner.Site.Name : nestedSite.FullName);
90 }
91 return result;
92 }
93 }
94
96 {
97 Owner = owner ?? throw new ArgumentNullException("owner");
98 Owner.Disposed += OnOwnerDisposed;
99 }
100
101 protected override ISite CreateSite(IComponent component, string? name)
102 {
103 if (component == null)
104 {
105 throw new ArgumentNullException("component");
106 }
107 return new Site(component, this, name);
108 }
109
110 protected override void Dispose(bool disposing)
111 {
112 if (disposing)
113 {
114 Owner.Disposed -= OnOwnerDisposed;
115 }
116 base.Dispose(disposing);
117 }
118
119 protected override object? GetService(Type service)
120 {
121 if (service == typeof(INestedContainer))
122 {
123 return this;
124 }
125 return base.GetService(service);
126 }
127
128 private void OnOwnerDisposed(object sender, EventArgs e)
129 {
130 Dispose();
131 }
132}
Site(IComponent component, NestedContainer container, string name)
override ISite CreateSite(IComponent component, string? name)
void OnOwnerDisposed(object sender, EventArgs e)
override? object GetService(Type service)
override void Dispose(bool disposing)