Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PropertyDescriptor.cs
Go to the documentation of this file.
4
6
7public abstract class PropertyDescriptor : MemberDescriptor
8{
10
12
13 private object[] _editors;
14
15 private Type[] _editorTypes;
16
17 private int _editorCount;
18
19 public abstract Type ComponentType { get; }
20
21 public virtual TypeConverter Converter
22 {
23 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
24 get
25 {
27 if (_converter == null)
28 {
29 TypeConverterAttribute typeConverterAttribute = (TypeConverterAttribute)attributes[typeof(TypeConverterAttribute)];
30 if (typeConverterAttribute.ConverterTypeName != null && typeConverterAttribute.ConverterTypeName.Length > 0)
31 {
32 Type typeFromName = GetTypeFromName(typeConverterAttribute.ConverterTypeName);
33 if (typeFromName != null && typeof(TypeConverter).IsAssignableFrom(typeFromName))
34 {
36 }
37 }
38 if (_converter == null)
39 {
41 }
42 }
43 return _converter;
44 }
45 }
46
47 public virtual bool IsLocalizable => LocalizableAttribute.Yes.Equals(Attributes[typeof(LocalizableAttribute)]);
48
49 public abstract bool IsReadOnly { get; }
50
52 {
53 get
54 {
56 return designerSerializationVisibilityAttribute.Visibility;
57 }
58 }
59
60 public abstract Type PropertyType { get; }
61
62 public virtual bool SupportsChangeEvents => false;
63
64 protected PropertyDescriptor(string name, Attribute[]? attrs)
65 : base(name, attrs)
66 {
67 }
68
70 : base(descr)
71 {
72 }
73
75 : base(descr, attrs)
76 {
77 }
78
79 public virtual void AddValueChanged(object component, EventHandler handler)
80 {
81 if (component == null)
82 {
83 throw new ArgumentNullException("component");
84 }
85 if (handler == null)
86 {
87 throw new ArgumentNullException("handler");
88 }
89 if (_valueChangedHandlers == null)
90 {
92 }
93 EventHandler a = (EventHandler)_valueChangedHandlers[component];
94 _valueChangedHandlers[component] = Delegate.Combine(a, handler);
95 }
96
97 public abstract bool CanResetValue(object component);
98
99 public override bool Equals([NotNullWhen(true)] object? obj)
100 {
101 try
102 {
103 if (obj == this)
104 {
105 return true;
106 }
107 if (obj == null)
108 {
109 return false;
110 }
111 if (obj is PropertyDescriptor propertyDescriptor && propertyDescriptor.NameHashCode == NameHashCode && propertyDescriptor.PropertyType == PropertyType && propertyDescriptor.Name.Equals(Name))
112 {
113 return true;
114 }
115 }
116 catch
117 {
118 }
119 return false;
120 }
121
122 protected object? CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
123 {
124 Type[] array = new Type[1] { typeof(Type) };
125 ConstructorInfo constructor = type.GetConstructor(array);
126 if (constructor != null)
127 {
128 return TypeDescriptor.CreateInstance(null, type, array, new object[1] { PropertyType });
129 }
130 return TypeDescriptor.CreateInstance(null, type, null, null);
131 }
132
133 protected override void FillAttributes(IList attributeList)
134 {
135 _converter = null;
136 _editors = null;
137 _editorTypes = null;
138 _editorCount = 0;
139 base.FillAttributes(attributeList);
140 }
141
142 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
144 {
145 return GetChildProperties(null, null);
146 }
147
148 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
150 {
151 return GetChildProperties(null, filter);
152 }
153
154 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of instance cannot be statically discovered.")]
156 {
157 return GetChildProperties(instance, null);
158 }
159
160 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of instance cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
161 public virtual PropertyDescriptorCollection GetChildProperties(object? instance, Attribute[]? filter)
162 {
163 if (instance == null)
164 {
166 }
167 return TypeDescriptor.GetProperties(instance, filter);
168 }
169
170 [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. PropertyDescriptor's PropertyType cannot be statically discovered.")]
171 public virtual object? GetEditor(Type editorBaseType)
172 {
173 object obj = null;
174 AttributeCollection attributes = Attributes;
175 if (_editorTypes != null)
176 {
177 for (int i = 0; i < _editorCount; i++)
178 {
179 if (_editorTypes[i] == editorBaseType)
180 {
181 return _editors[i];
182 }
183 }
184 }
185 if (obj == null)
186 {
187 for (int j = 0; j < attributes.Count; j++)
188 {
189 if (!(attributes[j] is EditorAttribute editorAttribute))
190 {
191 continue;
192 }
193 Type typeFromName = GetTypeFromName(editorAttribute.EditorBaseTypeName);
194 if (editorBaseType == typeFromName)
195 {
196 Type typeFromName2 = GetTypeFromName(editorAttribute.EditorTypeName);
197 if (typeFromName2 != null)
198 {
199 obj = CreateInstance(typeFromName2);
200 break;
201 }
202 }
203 }
204 if (obj == null)
205 {
206 obj = TypeDescriptor.GetEditor(PropertyType, editorBaseType);
207 }
208 if (_editorTypes == null)
209 {
210 _editorTypes = new Type[5];
211 _editors = new object[5];
212 }
213 if (_editorCount >= _editorTypes.Length)
214 {
215 Type[] array = new Type[_editorTypes.Length * 2];
216 object[] array2 = new object[_editors.Length * 2];
218 Array.Copy(_editors, array2, _editors.Length);
220 _editors = array2;
221 }
222 _editorTypes[_editorCount] = editorBaseType;
224 }
225 return obj;
226 }
227
228 public override int GetHashCode()
229 {
231 }
232
233 protected override object? GetInvocationTarget(Type type, object instance)
234 {
235 object obj = base.GetInvocationTarget(type, instance);
236 if (obj is ICustomTypeDescriptor customTypeDescriptor)
237 {
238 obj = customTypeDescriptor.GetPropertyOwner(this);
239 }
240 return obj;
241 }
242
243 [RequiresUnreferencedCode("Calls ComponentType.Assembly.GetType on the non-fully qualified typeName, which the trimmer cannot recognize.")]
244 [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
245 protected Type? GetTypeFromName([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string? typeName)
246 {
247 if (typeName == null || typeName.Length == 0)
248 {
249 return null;
250 }
251 Type type = Type.GetType(typeName);
252 Type type2 = null;
253 if (ComponentType != null && (type == null || ComponentType.Assembly.FullName.Equals(type.Assembly.FullName)))
254 {
255 int num = typeName.IndexOf(',');
256 if (num != -1)
257 {
258 typeName = typeName.Substring(0, num);
259 }
260 type2 = ComponentType.Assembly.GetType(typeName);
261 }
262 return type2 ?? type;
263 }
264
265 public abstract object? GetValue(object? component);
266
267 protected virtual void OnValueChanged(object? component, EventArgs e)
268 {
269 if (component != null)
270 {
271 ((EventHandler)(_valueChangedHandlers?[component]))?.Invoke(component, e);
272 }
273 }
274
275 public virtual void RemoveValueChanged(object component, EventHandler handler)
276 {
277 if (component == null)
278 {
279 throw new ArgumentNullException("component");
280 }
281 if (handler == null)
282 {
283 throw new ArgumentNullException("handler");
284 }
285 if (_valueChangedHandlers != null)
286 {
287 EventHandler source = (EventHandler)_valueChangedHandlers[component];
289 if (source != null)
290 {
291 _valueChangedHandlers[component] = source;
292 }
293 else
294 {
295 _valueChangedHandlers.Remove(component);
296 }
297 }
298 }
299
300 protected internal EventHandler? GetValueChangedHandler(object component)
301 {
302 if (component != null && _valueChangedHandlers != null)
303 {
304 return (EventHandler)_valueChangedHandlers[component];
305 }
306 return null;
307 }
308
309 public abstract void ResetValue(object component);
310
311 public abstract void SetValue(object? component, object? value);
312
313 public abstract bool ShouldSerializeValue(object component);
314}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
virtual void Remove(object key)
static readonly LocalizableAttribute Yes
virtual AttributeCollection Attributes
virtual void OnValueChanged(object? component, EventArgs e)
void SetValue(object? component, object? value)
EventHandler? GetValueChangedHandler(object component)
override void FillAttributes(IList attributeList)
PropertyDescriptor(string name, Attribute[]? attrs)
PropertyDescriptorCollection GetChildProperties()
PropertyDescriptorCollection GetChildProperties(object instance)
object? CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
bool CanResetValue(object component)
virtual void RemoveValueChanged(object component, EventHandler handler)
virtual ? object GetEditor(Type editorBaseType)
PropertyDescriptorCollection GetChildProperties(Attribute[] filter)
override bool Equals([NotNullWhen(true)] object? obj)
bool ShouldSerializeValue(object component)
virtual PropertyDescriptorCollection GetChildProperties(object? instance, Attribute[]? filter)
override? object GetInvocationTarget(Type type, object instance)
virtual void AddValueChanged(object component, EventHandler handler)
Type? GetTypeFromName([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string? typeName)
object? GetValue(object? component)
PropertyDescriptor(MemberDescriptor descr, Attribute[]? attrs)
DesignerSerializationVisibility SerializationVisibility
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static ? object GetEditor(object component, Type editorBaseType)
static TypeConverter GetConverter(object component)
static ? object CreateInstance(IServiceProvider? provider, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, Type[]? argTypes, object[]? args)
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
virtual ? string FullName
Definition Assembly.cs:74
virtual ? Type GetType(string name)
Definition Assembly.cs:305
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
override int GetHashCode()
Definition Type.cs:1122
Assembly Assembly
Definition Type.cs:49
delegate void EventHandler(object? sender, EventArgs e)