Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ColumnTypeConverter.cs
Go to the documentation of this file.
7
8namespace System.Data;
9
10internal sealed class ColumnTypeConverter : TypeConverter
11{
12 private static readonly Type[] s_types = new Type[35]
13 {
14 typeof(bool),
15 typeof(byte),
16 typeof(byte[]),
17 typeof(char),
18 typeof(DateTime),
19 typeof(decimal),
20 typeof(double),
21 typeof(Guid),
22 typeof(short),
23 typeof(int),
24 typeof(long),
25 typeof(object),
26 typeof(sbyte),
27 typeof(float),
28 typeof(string),
29 typeof(TimeSpan),
30 typeof(ushort),
31 typeof(uint),
32 typeof(ulong),
33 typeof(SqlInt16),
34 typeof(SqlInt32),
35 typeof(SqlInt64),
36 typeof(SqlDecimal),
37 typeof(SqlSingle),
38 typeof(SqlDouble),
39 typeof(SqlString),
40 typeof(SqlBoolean),
41 typeof(SqlBinary),
42 typeof(SqlByte),
43 typeof(SqlDateTime),
44 typeof(SqlGuid),
45 typeof(SqlMoney),
46 typeof(SqlBytes),
47 typeof(SqlChars),
48 typeof(SqlXml)
49 };
50
52
53 public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
54 {
55 if (!(destinationType == typeof(InstanceDescriptor)))
56 {
57 return base.CanConvertTo(context, destinationType);
58 }
59 return true;
60 }
61
62 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "InstanceDescriptor calls GetType(string) on AssemblyQualifiedName of instance of type we already have in here.")]
63 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
64 {
65 if (destinationType == null)
66 {
67 throw new ArgumentNullException("destinationType");
68 }
69 if (destinationType == typeof(string))
70 {
71 if (value == null)
72 {
73 return string.Empty;
74 }
75 return value.ToString();
76 }
77 if (value != null && destinationType == typeof(InstanceDescriptor))
78 {
79 object obj = value;
80 if (value is string)
81 {
82 for (int i = 0; i < s_types.Length; i++)
83 {
84 if (s_types[i].ToString().Equals(value))
85 {
86 obj = s_types[i];
87 }
88 }
89 }
90 if (value is Type || value is string)
91 {
92 MethodInfo method = typeof(Type).GetMethod("GetType", new Type[1] { typeof(string) });
93 if (method != null)
94 {
95 return new InstanceDescriptor(method, new object[1] { ((Type)obj).AssemblyQualifiedName });
96 }
97 }
98 }
99 return base.ConvertTo(context, culture, value, destinationType);
100 }
101
102 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
103 {
104 if (!(sourceType == typeof(string)))
105 {
106 return base.CanConvertTo(context, sourceType);
107 }
108 return true;
109 }
110
111 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
112 {
113 if (value != null && value.GetType() == typeof(string))
114 {
115 for (int i = 0; i < s_types.Length; i++)
116 {
117 if (s_types[i].ToString().Equals(value))
118 {
119 return s_types[i];
120 }
121 }
122 return typeof(string);
123 }
124 return base.ConvertFrom(context, culture, value);
125 }
126
128 {
129 if (_values == null)
130 {
131 object[] array;
132 if (s_types != null)
133 {
134 array = new object[s_types.Length];
135 Array.Copy(s_types, array, s_types.Length);
136 }
137 else
138 {
139 array = null;
140 }
142 }
143 return _values;
144 }
145
147 {
148 return true;
149 }
150
152 {
153 return true;
154 }
155}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
override bool GetStandardValuesSupported(ITypeDescriptorContext context)
override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
StandardValuesCollection _values
override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)