Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ReflectTypeDescriptionProvider.cs
Go to the documentation of this file.
6using System.Linq;
11
12namespace System.ComponentModel;
13
15{
43
44 private sealed class ReflectedTypeData
45 {
47 private readonly Type _type;
48
50
52
54
56
57 private object[] _editors;
58
59 private Type[] _editorTypes;
60
61 private int _editorCount;
62
63 internal bool IsPopulated => (_attributes != null) | (_events != null) | (_properties != null);
64
69
70 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2062:UnrecognizedReflectionPattern", Justification = "_type is annotated as preserve All members, so any Types returned from GetInterfaces should be preserved as well once https://github.com/mono/linker/issues/1731 is fixed.")]
72 {
73 if (_attributes == null)
74 {
77 while (baseType != null && baseType != typeof(object))
78 {
80 baseType = baseType.BaseType;
81 }
82 int count = list.Count;
83 Type[] interfaces = _type.GetInterfaces();
84 foreach (Type type in interfaces)
85 {
86 if ((type.Attributes & TypeAttributes.NestedPrivate) != 0)
87 {
88 list.AddRange(TypeDescriptor.GetAttributes(type).Attributes);
89 }
90 }
91 if (list.Count != 0)
92 {
94 int num = 0;
95 for (int j = 0; j < list.Count; j++)
96 {
98 bool flag = true;
99 if (j >= count)
100 {
101 for (int k = 0; k < s_skipInterfaceAttributeList.Length; k++)
102 {
103 if (s_skipInterfaceAttributeList[k].IsInstanceOfType(attribute))
104 {
105 flag = false;
106 break;
107 }
108 }
109 }
110 if (flag && hashSet.Add(attribute.TypeId))
111 {
112 list[num++] = list[j];
113 }
114 }
115 list.RemoveRange(num, list.Count - num);
116 }
117 _attributes = new AttributeCollection(list.ToArray());
118 }
119 return _attributes;
120 }
121
122 internal string GetClassName(object instance)
123 {
124 return _type.FullName;
125 }
126
127 internal string GetComponentName(object instance)
128 {
129 ISite site = ((instance is IComponent component) ? component.Site : null);
130 if (site != null)
131 {
132 return ((site is INestedSite nestedSite) ? nestedSite.FullName : null) ?? site.Name;
133 }
134 return null;
135 }
136
137 [RequiresUnreferencedCode("NullableConverter's UnderlyingType cannot be statically discovered. The Type of instance cannot be statically discovered.")]
175
176 [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
177 internal EventDescriptor GetDefaultEvent(object instance)
178 {
181 if (defaultEventAttribute != null && defaultEventAttribute.Name != null)
182 {
183 if (instance != null)
184 {
185 return TypeDescriptor.GetEvents(instance)[defaultEventAttribute.Name];
186 }
188 }
189 return null;
190 }
191
192 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of instance cannot be statically discovered.")]
207
208 [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The Type of instance cannot be statically discovered.")]
209 internal object GetEditor(object instance, Type editorBaseType)
210 {
212 if (instance != null)
213 {
217 {
219 if (typeFromName != null && editorBaseType.IsAssignableFrom(typeFromName))
220 {
222 }
223 }
224 }
225 lock (this)
226 {
227 for (int i = 0; i < _editorCount; i++)
228 {
230 {
231 return _editors[i];
232 }
233 }
234 }
235 object obj = null;
237 if (editorAttribute != null)
238 {
240 if (typeFromName2 != null && editorBaseType.IsAssignableFrom(typeFromName2))
241 {
243 }
244 }
245 if (obj == null)
246 {
248 if (editorTable != null)
249 {
251 }
252 if (obj != null && !editorBaseType.IsInstanceOfType(obj))
253 {
254 obj = null;
255 }
256 }
257 if (obj != null)
258 {
259 lock (this)
260 {
261 if (_editorTypes == null || _editorTypes.Length == _editorCount)
262 {
263 int num = ((_editorTypes == null) ? 4 : (_editorTypes.Length * 2));
264 Type[] array = new Type[num];
265 object[] array2 = new object[num];
266 if (_editorTypes != null)
267 {
268 _editorTypes.CopyTo(array, 0);
269 _editors.CopyTo(array2, 0);
270 }
275 }
276 }
277 }
278 return obj;
279 }
280
282 {
283 foreach (Attribute attribute in attributes)
284 {
286 {
287 Type type = Type.GetType(editorAttribute.EditorBaseTypeName);
288 if (type != null && type == editorBaseType)
289 {
290 return editorAttribute;
291 }
292 }
293 }
294 return null;
295 }
296
298 {
299 if (_events == null)
300 {
302 Type type = _type;
303 Type typeFromHandle = typeof(object);
305 do
306 {
310 {
312 }
313 type = type.BaseType;
314 }
315 while (type != null && type != typeFromHandle);
316 array = new EventDescriptor[dictionary.Count];
317 dictionary.Values.CopyTo(array, 0);
319 }
320 return _events;
321 }
322
323 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
325 {
326 if (_properties == null)
327 {
329 Type type = _type;
330 Type typeFromHandle = typeof(object);
332 do
333 {
337 {
339 }
340 type = type.BaseType;
341 }
342 while (type != null && type != typeFromHandle);
344 dictionary.Values.CopyTo(array, 0);
346 }
347 return _properties;
348 }
349
350 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Calling _type.Assembly.GetType on a non-assembly qualified type will still work. See https://github.com/mono/linker/issues/1895")]
351 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:TypeGetType", Justification = "Using the non-assembly qualified type name will still work.")]
353 {
354 if (string.IsNullOrEmpty(typeName))
355 {
356 return null;
357 }
358 int num = typeName.IndexOf(',');
359 Type type = null;
360 if (num == -1)
361 {
362 type = _type.Assembly.GetType(typeName);
363 }
364 if (type == null)
365 {
366 type = Type.GetType(typeName);
367 }
368 if (type == null && num != -1)
369 {
370 type = Type.GetType(typeName.Substring(0, num));
371 }
372 return type;
373 }
374
375 internal void Refresh()
376 {
377 _attributes = null;
378 _events = null;
379 _properties = null;
380 _converter = null;
381 _editors = null;
382 _editorTypes = null;
383 _editorCount = 0;
384 }
385 }
386
388
389 private static readonly Type[] s_typeConstructor = new Type[1] { typeof(Type) };
390
391 private static Hashtable s_editorTables;
392
394
395 private static readonly object s_intrinsicReferenceKey = new object();
396
397 private static readonly object s_intrinsicNullableKey = new object();
398
399 private static readonly object s_dictionaryKey = new object();
400
402
403 private static Hashtable s_eventCache;
404
406
408
409 private static readonly Guid s_extenderPropertiesKey = Guid.NewGuid();
410
412
413 private static readonly Type[] s_skipInterfaceAttributeList = new Type[1] { typeof(ComVisibleAttribute) };
414
415 private static readonly object s_internalSyncObject = new object();
416
417 internal static Guid ExtenderProviderKey { get; } = Guid.NewGuid();
418
419
420 private static Hashtable EditorTables => LazyInitializer.EnsureInitialized(ref s_editorTables, () => new Hashtable(4));
421
423 {
424 [RequiresUnreferencedCode("NullableConverter's UnderlyingType cannot be statically discovered.")]
425 get
426 {
428 {
430 [typeof(byte)] = new IntrinsicTypeConverterData((Type type) => new ByteConverter()),
431 [typeof(sbyte)] = new IntrinsicTypeConverterData((Type type) => new SByteConverter()),
432 [typeof(char)] = new IntrinsicTypeConverterData((Type type) => new CharConverter()),
433 [typeof(double)] = new IntrinsicTypeConverterData((Type type) => new DoubleConverter()),
434 [typeof(string)] = new IntrinsicTypeConverterData((Type type) => new StringConverter()),
436 [typeof(short)] = new IntrinsicTypeConverterData((Type type) => new Int16Converter()),
437 [typeof(long)] = new IntrinsicTypeConverterData((Type type) => new Int64Converter()),
438 [typeof(float)] = new IntrinsicTypeConverterData((Type type) => new SingleConverter()),
439 [typeof(ushort)] = new IntrinsicTypeConverterData((Type type) => new UInt16Converter()),
441 [typeof(ulong)] = new IntrinsicTypeConverterData((Type type) => new UInt64Converter()),
442 [typeof(object)] = new IntrinsicTypeConverterData((Type type) => new TypeConverter()),
446 [typeof(decimal)] = new IntrinsicTypeConverterData((Type type) => new DecimalConverter()),
456 });
457 }
458 }
459
460 private static Hashtable PropertyCache => LazyInitializer.EnsureInitialized(ref s_propertyCache, () => new Hashtable());
461
462 private static Hashtable EventCache => LazyInitializer.EnsureInitialized(ref s_eventCache, () => new Hashtable());
463
464 private static Hashtable AttributeCache => LazyInitializer.EnsureInitialized(ref s_attributeCache, () => new Hashtable());
465
466 private static Hashtable ExtendedPropertyCache => LazyInitializer.EnsureInitialized(ref s_extendedPropertyCache, () => new Hashtable());
467
469 {
470 }
471
472 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "IntrinsicTypeConverters is marked with RequiresUnreferencedCode. It is the only place that should call this.")]
474 {
475 return new NullableConverter(type);
476 }
477
478 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "Trimmer does not trim enums")]
480 {
481 return new EnumConverter(type);
482 }
483
484 internal static void ClearReflectionCaches()
485 {
486 s_propertyCache = null;
487 s_eventCache = null;
488 s_attributeCache = null;
490 }
491
492 [RequiresUnreferencedCode("The Types specified in table may be trimmed, or have their static construtors trimmed.")]
493 internal static void AddEditorTable(Type editorBaseType, Hashtable table)
494 {
495 if (editorBaseType == null)
496 {
497 throw new ArgumentNullException("editorBaseType");
498 }
500 {
503 {
505 }
506 }
507 }
508
510 {
511 object obj = null;
512 if (argTypes != null)
513 {
514 obj = objectType.GetConstructor(argTypes)?.Invoke(args);
515 }
516 else
517 {
518 if (args != null)
519 {
520 argTypes = new Type[args.Length];
521 for (int i = 0; i < args.Length; i++)
522 {
523 if (args[i] != null)
524 {
525 argTypes[i] = args[i].GetType();
526 }
527 else
528 {
529 argTypes[i] = typeof(object);
530 }
531 }
532 }
533 else
534 {
535 argTypes = Type.EmptyTypes;
536 }
537 obj = objectType.GetConstructor(argTypes)?.Invoke(args);
538 }
540 }
541
543 {
544 return objectType.GetConstructor(s_typeConstructor)?.Invoke(new object[1] { callingType }) ?? Activator.CreateInstance(objectType);
545 }
546
552
553 public override IDictionary GetCache(object instance)
554 {
555 if (instance is IComponent { Site: not null } component && component.Site.GetService(typeof(IDictionaryService)) is IDictionaryService dictionaryService)
556 {
558 if (dictionary == null)
559 {
560 dictionary = new Hashtable();
562 }
563 return dictionary;
564 }
565 return null;
566 }
567
573
575 {
577 return typeData.GetComponentName(instance);
578 }
579
580 [RequiresUnreferencedCode("NullableConverter's UnderlyingType cannot be statically discovered. The Type of instance cannot be statically discovered.")]
582 {
584 return typeData.GetConverter(instance);
585 }
586
587 [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
589 {
591 return typeData.GetDefaultEvent(instance);
592 }
593
594 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of instance cannot be statically discovered.")]
596 {
598 return typeData.GetDefaultProperty(instance);
599 }
600
601 [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The Type of instance cannot be statically discovered.")]
603 {
605 return typeData.GetEditor(instance, editorBaseType);
606 }
607
608 [RequiresUnreferencedCode("The Types specified in EditorTables may be trimmed, or have their static construtors trimmed.")]
610 {
613 if (obj == null)
614 {
617 if (obj == null)
618 {
620 {
622 if (obj == null)
623 {
625 }
626 }
627 }
628 }
629 if (obj == editorTables)
630 {
631 obj = null;
632 }
633 return (Hashtable)obj;
634 }
635
641
643 {
645 }
646
647 [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
648 internal string GetExtendedClassName(object instance)
649 {
650 return GetClassName(instance.GetType());
651 }
652
653 [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
654 internal string GetExtendedComponentName(object instance)
655 {
656 return GetComponentName(instance.GetType(), instance);
657 }
658
659 [RequiresUnreferencedCode("The Type of instance cannot be statically discovered. NullableConverter's UnderlyingType cannot be statically discovered.")]
660 internal TypeConverter GetExtendedConverter(object instance)
661 {
662 return GetConverter(instance.GetType(), instance);
663 }
664
665 internal EventDescriptor GetExtendedDefaultEvent(object instance)
666 {
667 return null;
668 }
669
671 {
672 return null;
673 }
674
675 [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The Type of instance cannot be statically discovered.")]
676 internal object GetExtendedEditor(object instance, Type editorBaseType)
677 {
678 return GetEditor(instance.GetType(), instance, editorBaseType);
679 }
680
682 {
684 }
685
686 [RequiresUnreferencedCode("The Type of instance and its IExtenderProviders cannot be statically discovered.")]
688 {
689 Type type = instance.GetType();
692 if (extenderProviders.Length == 0)
693 {
695 }
697 if (cache != null)
698 {
700 }
702 {
704 }
706 for (int i = 0; i < extenderProviders.Length; i++)
707 {
709 if (list == null)
710 {
712 }
714 {
716 {
718 if (receiverType != null && receiverType.IsAssignableFrom(type))
719 {
721 }
722 }
723 }
724 }
725 if (list != null)
726 {
728 list.CopyTo(array2, 0);
730 }
731 else
732 {
734 }
735 if (cache != null)
736 {
738 }
740 }
741
742 protected internal override IExtenderProvider[] GetExtenderProviders(object instance)
743 {
744 if (instance == null)
745 {
746 throw new ArgumentNullException("instance");
747 }
748 if (instance is IComponent { Site: not null } component)
749 {
752 if (extenderListService != null)
753 {
754 return GetExtenders(extenderListService.GetExtenderProviders(), instance, cache);
755 }
756 }
757 return Array.Empty<IExtenderProvider>();
758 }
759
761 {
762 bool flag = false;
763 int num = 0;
764 IExtenderProvider[] array = null;
765 ulong num2 = 0uL;
766 int num3 = 64;
768 if (cache != null)
769 {
771 }
772 if (array == null)
773 {
774 flag = true;
775 }
776 int num4 = 0;
777 int num5 = 0;
778 if (array2 != null)
779 {
780 for (num4 = 0; num4 < array2.Length; num4++)
781 {
782 if (array2[num4].CanExtend(instance))
783 {
784 num++;
785 if (num4 < num3)
786 {
787 num2 |= (ulong)(1L << num4);
788 }
789 if (!flag && (num5 >= array.Length || array2[num4] != array[num5++]))
790 {
791 flag = true;
792 }
793 }
794 }
795 }
796 else if (components != null)
797 {
798 foreach (object component in components)
799 {
801 {
802 num++;
803 if (num4 < num3)
804 {
805 num2 |= (ulong)(1L << num4);
806 }
807 if (!flag && (num5 >= array.Length || extenderProvider != array[num5++]))
808 {
809 flag = true;
810 }
811 }
812 num4++;
813 }
814 }
815 if (array != null && num != array.Length)
816 {
817 flag = true;
818 }
819 if (flag)
820 {
821 if (array2 == null || num != array2.Length)
822 {
824 num4 = 0;
825 num5 = 0;
826 if (array2 != null && num > 0)
827 {
828 for (; num4 < array2.Length; num4++)
829 {
830 if ((num4 < num3 && (num2 & (ulong)(1L << num4)) != 0L) || (num4 >= num3 && array2[num4].CanExtend(instance)))
831 {
832 array3[num5++] = array2[num4];
833 }
834 }
835 }
836 else if (num > 0)
837 {
838 foreach (object component2 in components)
839 {
840 if (component2 is IExtenderProvider extenderProvider2 && ((num4 < num3 && (num2 & (ulong)(1L << num4)) != 0L) || (num4 >= num3 && extenderProvider2.CanExtend(instance))))
841 {
843 }
844 num4++;
845 }
846 }
847 array2 = array3;
848 }
849 if (cache != null)
850 {
853 }
854 }
855 else
856 {
857 array2 = array;
858 }
859 return array2;
860 }
861
862 internal object GetExtendedPropertyOwner(object instance, PropertyDescriptor pd)
863 {
864 return GetPropertyOwner(instance.GetType(), instance, pd);
865 }
866
867 [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
868 public override ICustomTypeDescriptor GetExtendedTypeDescriptor(object instance)
869 {
870 return null;
871 }
872
873 [RequiresUnreferencedCode("The Type of component cannot be statically discovered.")]
874 public override string GetFullComponentName(object component)
875 {
877 {
878 return nestedSite.FullName;
879 }
881 }
882
884 {
885 List<Type> list = new List<Type>();
887 {
889 if (typeData != null)
890 {
892 while (enumerator.MoveNext())
893 {
895 Type type = (Type)entry.Key;
896 if (type.Module == module && ((ReflectedTypeData)entry.Value).IsPopulated)
897 {
898 list.Add(type);
899 }
900 }
901 }
902 }
903 return list.ToArray();
904 }
905
906 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
912
913 internal object GetPropertyOwner(Type type, object instance, PropertyDescriptor pd)
914 {
915 return TypeDescriptor.GetAssociation(type, instance);
916 }
917
918 [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields)]
919 public override Type GetReflectionType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields)] Type objectType, object instance)
920 {
921 return objectType;
922 }
923
925 {
927 if (_typeData != null)
928 {
930 if (reflectedTypeData != null)
931 {
932 return reflectedTypeData;
933 }
934 }
936 {
937 if (_typeData != null)
938 {
940 }
941 if (reflectedTypeData == null && createIfNeeded)
942 {
944 if (_typeData == null)
945 {
946 _typeData = new Hashtable();
947 }
949 }
950 }
951 return reflectedTypeData;
952 }
953
955 {
956 return null;
957 }
958
959 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:TypeGetType", Justification = "typeName is annotated with DynamicallyAccessedMembers, which will preserve the type. Using the non-assembly qualified type name will still work.")]
960 private static Type GetTypeFromName([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string typeName)
961 {
962 Type type = Type.GetType(typeName);
963 if (type == null)
964 {
965 int num = typeName.IndexOf(',');
966 if (num != -1)
967 {
968 type = Type.GetType(typeName.Substring(0, num));
969 }
970 }
971 return type;
972 }
973
974 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "ReflectedTypeData is not being created here, just checking if was already created.")]
975 internal bool IsPopulated(Type type)
976 {
977 return GetTypeData(type, createIfNeeded: false)?.IsPopulated ?? false;
978 }
979
981 {
984 if (array != null)
985 {
986 return array;
987 }
989 {
991 if (array == null)
992 {
993 array = (Attribute[])(attributeCache[type] = type.GetCustomAttributes(typeof(Attribute), inherit: false).OfType<Attribute>().ToArray());
994 }
995 }
996 return array;
997 }
998
999 internal static Attribute[] ReflectGetAttributes(MemberInfo member)
1000 {
1002 Attribute[] array = (Attribute[])attributeCache[member];
1003 if (array != null)
1004 {
1005 return array;
1006 }
1008 {
1009 array = (Attribute[])attributeCache[member];
1010 if (array == null)
1011 {
1012 array = (Attribute[])(attributeCache[member] = member.GetCustomAttributes(typeof(Attribute), inherit: false).OfType<Attribute>().ToArray());
1013 }
1014 }
1015 return array;
1016 }
1017
1019 {
1022 if (array != null)
1023 {
1024 return array;
1025 }
1027 {
1029 if (array == null)
1030 {
1031 BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public;
1032 EventInfo[] events = type.GetEvents(bindingAttr);
1033 array = new EventDescriptor[events.Length];
1034 int num = 0;
1035 foreach (EventInfo eventInfo in events)
1036 {
1037 if ((eventInfo.DeclaringType.IsPublic || eventInfo.DeclaringType.IsNestedPublic || !(eventInfo.DeclaringType.Assembly == typeof(ReflectTypeDescriptionProvider).Assembly)) && eventInfo.AddMethod != null && eventInfo.RemoveMethod != null)
1038 {
1040 }
1041 }
1042 if (num != array.Length)
1043 {
1045 Array.Copy(array, array2, num);
1046 array = array2;
1047 }
1049 }
1050 }
1051 return array;
1052 }
1053
1054 [RequiresUnreferencedCode("The type of provider cannot be statically discovered.")]
1056 {
1059 {
1060 return result;
1061 }
1062 Type type = provider.GetType();
1065 if (array == null)
1066 {
1068 {
1070 if (array == null)
1071 {
1074 foreach (Attribute item in attributes)
1075 {
1077 {
1078 continue;
1079 }
1081 if (!(typeFromName != null))
1082 {
1083 continue;
1084 }
1085 MethodInfo method = type.GetMethod("Get" + providePropertyAttribute.PropertyName, new Type[1] { typeFromName });
1086 if (method != null && !method.IsStatic && method.IsPublic)
1087 {
1088 MethodInfo methodInfo = type.GetMethod("Set" + providePropertyAttribute.PropertyName, new Type[2] { typeFromName, method.ReturnType });
1089 if (methodInfo != null && (methodInfo.IsStatic || !methodInfo.IsPublic))
1090 {
1091 methodInfo = null;
1092 }
1094 }
1095 }
1097 list.CopyTo(array, 0);
1099 }
1100 }
1101 }
1103 for (int i = 0; i < array.Length; i++)
1104 {
1107 }
1108 if (cache != null)
1109 {
1111 }
1112 return array2;
1113 }
1114
1115 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
1117 {
1120 if (array != null)
1121 {
1122 return array;
1123 }
1125 {
1127 if (array == null)
1128 {
1129 BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public;
1130 PropertyInfo[] properties = type.GetProperties(bindingAttr);
1131 array = new PropertyDescriptor[properties.Length];
1132 int num = 0;
1133 foreach (PropertyInfo propertyInfo in properties)
1134 {
1135 if (propertyInfo.GetIndexParameters().Length == 0)
1136 {
1137 MethodInfo getMethod = propertyInfo.GetGetMethod(nonPublic: false);
1138 MethodInfo setMethod = propertyInfo.GetSetMethod(nonPublic: false);
1139 string name = propertyInfo.Name;
1140 if (getMethod != null)
1141 {
1142 array[num++] = new ReflectPropertyDescriptor(type, name, propertyInfo.PropertyType, propertyInfo, getMethod, setMethod, null);
1143 }
1144 }
1145 }
1146 if (num != array.Length)
1147 {
1149 Array.Copy(array, array2, num);
1150 array = array2;
1151 }
1153 }
1154 }
1155 return array;
1156 }
1157
1158 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "ReflectedTypeData is not being created here, just checking if was already created.")]
1159 internal void Refresh(Type type)
1160 {
1162 }
1163
1164 [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")]
1165 private static object GetIntrinsicTypeEditor(Hashtable table, Type callingType)
1166 {
1167 object obj = null;
1168 lock (table)
1169 {
1171 while (type != null && type != typeof(object))
1172 {
1173 obj = table[type];
1174 if (obj is string typeName)
1175 {
1176 obj = Type.GetType(typeName);
1177 if (obj != null)
1178 {
1179 table[type] = obj;
1180 }
1181 }
1182 if (obj != null)
1183 {
1184 break;
1185 }
1186 type = type.BaseType;
1187 }
1188 if (obj == null)
1189 {
1191 while (enumerator.MoveNext())
1192 {
1194 Type type2 = entry.Key as Type;
1195 if (!(type2 != null) || !type2.IsInterface || !type2.IsAssignableFrom(callingType))
1196 {
1197 continue;
1198 }
1199 obj = entry.Value;
1200 if (obj is string typeName2)
1201 {
1203 if (obj != null)
1204 {
1205 table[callingType] = obj;
1206 }
1207 }
1208 if (obj != null)
1209 {
1210 break;
1211 }
1212 }
1213 }
1214 if (obj == null)
1215 {
1216 if (callingType.IsGenericType && callingType.GetGenericTypeDefinition() == typeof(Nullable<>))
1217 {
1218 obj = table[s_intrinsicNullableKey];
1219 }
1220 else if (callingType.IsInterface)
1221 {
1223 }
1224 }
1225 if (obj == null)
1226 {
1227 obj = table[typeof(object)];
1228 }
1229 Type type3 = obj as Type;
1230 if (type3 != null)
1231 {
1233 if (type3.GetConstructor(s_typeConstructor) == null)
1234 {
1235 table[callingType] = obj;
1236 }
1237 }
1238 }
1239 return obj;
1240 }
1241
1242 [RequiresUnreferencedCode("NullableConverter's UnderlyingType cannot be statically discovered.")]
1244 {
1246 {
1247 if (!IntrinsicTypeConverters.TryGetValue(callingType, out var value))
1248 {
1249 if (callingType.IsEnum)
1250 {
1252 }
1253 else if (callingType.IsArray)
1254 {
1256 }
1257 else if (callingType.IsGenericType && callingType.GetGenericTypeDefinition() == typeof(Nullable<>))
1258 {
1260 }
1261 else if (typeof(ICollection).IsAssignableFrom(callingType))
1262 {
1264 }
1265 else if (callingType.IsInterface)
1266 {
1268 }
1269 else
1270 {
1271 Type type = null;
1272 Type baseType = callingType.BaseType;
1273 while (baseType != null && baseType != typeof(object))
1274 {
1276 {
1277 type = baseType;
1278 break;
1279 }
1280 baseType = baseType.BaseType;
1281 }
1282 if ((object)type == null)
1283 {
1284 type = typeof(object);
1285 }
1287 }
1288 }
1289 return value.GetOrCreateConverterInstance(callingType);
1290 }
1291 }
1292}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
bool TryAdd(TKey key, TValue value)
void Add(TKey key, TValue value)
IEnumerator IEnumerable. GetEnumerator()
Definition Hashtable.cs:899
static readonly AttributeCollection Empty
static readonly EventDescriptorCollection Empty
static readonly PropertyDescriptorCollection Empty
IntrinsicTypeConverterData(Func< Type, TypeConverter > constructionFunc, bool cacheConverterInstance=true)
ReflectedTypeData([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
static EditorAttribute GetEditorAttribute(AttributeCollection attributes, Type editorBaseType)
Type GetTypeFromName([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName)
static object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, Type callingType)
string GetClassName([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
static object GetIntrinsicTypeEditor(Hashtable table, Type callingType)
static void AddEditorTable(Type editorBaseType, Hashtable table)
override ICustomTypeDescriptor GetExtendedTypeDescriptor(object instance)
object GetExtendedEditor(object instance, Type editorBaseType)
override Type GetReflectionType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor|DynamicallyAccessedMemberTypes.PublicFields)] Type objectType, object instance)
object GetPropertyOwner(Type type, object instance, PropertyDescriptor pd)
static EventDescriptor[] ReflectGetEvents([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
static PropertyDescriptor[] ReflectGetExtendedProperties(IExtenderProvider provider)
static Dictionary< object, IntrinsicTypeConverterData > s_intrinsicTypeConverters
PropertyDescriptorCollection GetExtendedProperties(object instance)
static Dictionary< object, IntrinsicTypeConverterData > IntrinsicTypeConverters
EventDescriptorCollection GetEvents([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
TypeConverter GetConverter([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object instance)
ReflectedTypeData GetTypeData([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, bool createIfNeeded)
EventDescriptor GetDefaultEvent([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object instance)
override ICustomTypeDescriptor GetTypeDescriptor([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type objectType, object instance)
object GetEditor([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object instance, Type editorBaseType)
PropertyDescriptor GetDefaultProperty([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object instance)
static PropertyDescriptor[] ReflectGetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
string GetComponentName([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object instance)
static Type GetTypeFromName([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string typeName)
object GetExtendedPropertyOwner(object instance, PropertyDescriptor pd)
override object CreateInstance(IServiceProvider provider, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, Type[] argTypes, object[] args)
override IExtenderProvider[] GetExtenderProviders(object instance)
PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
AttributeCollection GetAttributes([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
static IExtenderProvider[] GetExtenders(ICollection components, object instance, IDictionary cache)
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static EventDescriptorCollection GetEvents([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static object GetAssociation(Type type, object primary)
static ? string GetComponentName(object component)
static AttributeCollection GetAttributes([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static IDictionary GetCache(object instance)
virtual ? Type GetType(string name)
Definition Assembly.cs:305
object[] GetCustomAttributes(bool inherit)
ParameterInfo[] GetIndexParameters()
static void RunClassConstructor(QCallTypeHandle type)
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
Assembly Assembly
Definition Type.cs:49
Type? BaseType
Definition Type.cs:295
string? FullName
Definition Type.cs:47
Type[] GetInterfaces()
static readonly Type[] EmptyTypes
Definition Type.cs:19
static Guid NewGuid()
Definition Guid.cs:1283