Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WeakReference.cs
Go to the documentation of this file.
4
5namespace System;
6
8[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
9public class WeakReference : ISerializable
10{
11 internal IntPtr m_handle;
12
13 public virtual extern bool IsAlive
14 {
15 [MethodImpl(MethodImplOptions.InternalCall)]
16 get;
17 }
18
19 public virtual bool TrackResurrection => IsTrackResurrection();
20
21 public virtual extern object? Target
22 {
23 [MethodImpl(MethodImplOptions.InternalCall)]
24 get;
25 [MethodImpl(MethodImplOptions.InternalCall)]
26 set;
27 }
28
29 protected WeakReference()
30 {
31 throw new NotImplementedException();
32 }
33
34 [MethodImpl(MethodImplOptions.InternalCall)]
36
37 [MethodImpl(MethodImplOptions.InternalCall)]
38 private extern void Create(object target, bool trackResurrection);
39
40 [MethodImpl(MethodImplOptions.InternalCall)]
41 private extern bool IsTrackResurrection();
42
43 public WeakReference(object? target)
44 : this(target, trackResurrection: false)
45 {
46 }
47
48 public WeakReference(object? target, bool trackResurrection)
49 {
51 }
52
54 {
55 if (info == null)
56 {
57 throw new ArgumentNullException("info");
58 }
59 object value = info.GetValue("TrackedObject", typeof(object));
60 bool boolean = info.GetBoolean("TrackResurrection");
61 Create(value, boolean);
62 }
63
65 {
66 if (info == null)
67 {
68 throw new ArgumentNullException("info");
69 }
70 info.AddValue("TrackedObject", Target, typeof(object));
71 info.AddValue("TrackResurrection", IsTrackResurrection());
72 }
73}
74[Serializable]
75[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
76public sealed class WeakReference<T> : ISerializable where T : class?
77{
78 internal IntPtr m_handle;
79
80 private extern T Target
81 {
82 [MethodImpl(MethodImplOptions.InternalCall)]
83 [return: MaybeNull]
84 get;
85 [MethodImpl(MethodImplOptions.InternalCall)]
86 set;
87 }
88
89 public void SetTarget(T target)
90 {
91 Target = target;
92 }
93
94 [MethodImpl(MethodImplOptions.InternalCall)]
96
97 [MethodImpl(MethodImplOptions.InternalCall)]
98 private extern void Create(T target, bool trackResurrection);
99
100 [MethodImpl(MethodImplOptions.InternalCall)]
101 private extern bool IsTrackResurrection();
102
103 public WeakReference(T target)
104 : this(target, trackResurrection: false)
105 {
106 }
107
108 public WeakReference(T target, bool trackResurrection)
109 {
110 Create(target, trackResurrection);
111 }
112
114 {
115 if (info == null)
116 {
117 throw new ArgumentNullException("info");
118 }
119 T target = (T)info.GetValue("TrackedObject", typeof(T));
120 bool boolean = info.GetBoolean("TrackResurrection");
121 Create(target, boolean);
122 }
123
124 [MethodImpl(MethodImplOptions.AggressiveInlining)]
125 public bool TryGetTarget([MaybeNullWhen(false)][NotNullWhen(true)] out T target)
126 {
127 return (target = Target) != null;
128 }
129
131 {
132 if (info == null)
133 {
134 throw new ArgumentNullException("info");
135 }
136 info.AddValue("TrackedObject", Target, typeof(T));
137 info.AddValue("TrackResurrection", IsTrackResurrection());
138 }
139}
WeakReference(object? target, bool trackResurrection)
void Create(object target, bool trackResurrection)
WeakReference(SerializationInfo info, StreamingContext context)
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
virtual bool TrackResurrection
virtual ? object Target
WeakReference(T target, bool trackResurrection)
bool TryGetTarget([MaybeNullWhen(false)][NotNullWhen(true)] out T target)
void Create(T target, bool trackResurrection)
void SetTarget(T target)
WeakReference(object? target)
void GetObjectData(SerializationInfo info, StreamingContext context)