Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ConvertTo() [1/2]

override? object System.ComponentModel.EnumConverter.ConvertTo ( ITypeDescriptorContext? context,
CultureInfo? culture,
object? value,
Type destinationType )
inlinevirtual

Reimplemented from System.ComponentModel.TypeConverter.

Definition at line 90 of file EnumConverter.cs.

91 {
92 if (destinationType == null)
93 {
94 throw new ArgumentNullException("destinationType");
95 }
96 if (destinationType == typeof(string) && value != null)
97 {
98 if (!EnumType.IsDefined(typeof(FlagsAttribute), inherit: false) && !Enum.IsDefined(EnumType, value))
99 {
101 }
102 return Enum.Format(EnumType, value, "G");
103 }
105 {
106 string text = ConvertToInvariantString(context, value);
107 if (EnumType.IsDefined(typeof(FlagsAttribute), inherit: false) && text.Contains(','))
108 {
109 Type underlyingType = Enum.GetUnderlyingType(EnumType);
110 if (value is IConvertible)
111 {
112 object obj = ((IConvertible)value).ToType(underlyingType, culture);
113 MethodInfo method = typeof(Enum).GetMethod("ToObject", new Type[2]
114 {
115 typeof(Type),
117 });
118 if (method != null)
119 {
120 return new InstanceDescriptor(method, new object[2] { EnumType, obj });
121 }
122 }
123 }
124 else
125 {
127 if (field != null)
128 {
129 return new InstanceDescriptor(field, null);
130 }
131 }
132 }
133 if (destinationType == typeof(Enum[]) && value != null)
134 {
135 if (EnumType.IsDefined(typeof(FlagsAttribute), inherit: false))
136 {
137 bool isUnderlyingTypeUInt = Enum.GetUnderlyingType(EnumType) == typeof(ulong);
138 List<Enum> list = new List<Enum>();
139 Array values = Enum.GetValues(EnumType);
140 long[] array = new long[values.Length];
141 for (int i = 0; i < values.Length; i++)
142 {
144 }
146 bool flag = true;
147 while (flag)
148 {
149 flag = false;
150 long[] array2 = array;
151 foreach (long num2 in array2)
152 {
153 if ((num2 != 0L && (num2 & num) == num2) || num2 == num)
154 {
155 list.Add((Enum)Enum.ToObject(EnumType, num2));
156 flag = true;
157 num &= ~num2;
158 break;
159 }
160 }
161 if (num == 0L)
162 {
163 break;
164 }
165 }
166 if (!flag && num != 0L)
167 {
168 list.Add((Enum)Enum.ToObject(EnumType, num));
169 }
170 return list.ToArray();
171 }
172 return new Enum[1] { (Enum)Enum.ToObject(EnumType, value) };
173 }
174 return base.ConvertTo(context, culture, value, destinationType);
175 }
void Add(TKey key, TValue value)
static long GetEnumValue(bool isUnderlyingTypeUInt64, Enum enumVal, CultureInfo culture)
string? ConvertToInvariantString(object? value)
bool IsDefined(Type attributeType, bool inherit)
static string EnumConverterInvalidValue
Definition SR.cs:24
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
FieldInfo? GetField(string name)
Definition Type.cs:607

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.array, System.ComponentModel.TypeConverter.ConvertToInvariantString(), System.culture, System.Enum, System.SR.EnumConverterInvalidValue, System.ComponentModel.EnumConverter.EnumType, System.SR.Format(), System.Enum.Format(), System.ComponentModel.EnumConverter.GetEnumValue(), System.Type.GetField(), System.Enum.GetUnderlyingType(), System.Enum.GetValues(), System.Reflection.MemberInfo.IsDefined(), System.Enum.IsDefined(), System.L, System.list, System.Reflection.MemberInfo.Name, System.obj, System.text, System.Enum.ToObject(), System.value, and System.values.