Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TypeListConverter.cs
Go to the documentation of this file.
3
5
6public abstract class TypeListConverter : TypeConverter
7{
8 private readonly Type[] _types;
9
11
12 protected TypeListConverter(Type[] types)
13 {
14 _types = types;
15 }
16
17 public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
18 {
19 if (!(sourceType == typeof(string)))
20 {
21 return base.CanConvertFrom(context, sourceType);
22 }
23 return true;
24 }
25
26 public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
27 {
28 if (!(destinationType == typeof(InstanceDescriptor)))
29 {
30 return base.CanConvertTo(context, destinationType);
31 }
32 return true;
33 }
34
35 public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
36 {
37 if (value is string)
38 {
39 Type[] types = _types;
40 foreach (Type type in types)
41 {
42 if (value.Equals(type.FullName))
43 {
44 return type;
45 }
46 }
47 }
48 return base.ConvertFrom(context, culture, value);
49 }
50
51 public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
52 {
53 if (destinationType == null)
54 {
55 throw new ArgumentNullException("destinationType");
56 }
57 if (destinationType == typeof(string))
58 {
59 if (value == null)
60 {
61 return System.SR.none;
62 }
63 return ((Type)value).FullName;
64 }
65 return base.ConvertTo(context, culture, value, destinationType);
66 }
67
69 {
70 if (_values == null)
71 {
72 object[] array;
73 if (_types != null)
74 {
75 array = new object[_types.Length];
76 Array.Copy(_types, array, _types.Length);
77 }
78 else
79 {
80 array = null;
81 }
83 }
84 return _values;
85 }
86
88 {
89 return true;
90 }
91
93 {
94 return true;
95 }
96}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
override? object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context)
override? object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
static string none
Definition SR.cs:38
Definition SR.cs:7