93 Type oType = obj.GetType();
95 if (t.IsAssignableFrom(oType))
100 if (oType.IsGenericType && oType.GetGenericTypeDefinition() == typeof(
BadNullable<>))
102 Type innerType = oType.GetGenericArguments()[0];
106 return Activator.CreateInstance(typeof(
BadNullable<>).MakeGenericType(innerType));
109 return Activator.CreateInstance(typeof(
BadNullable<>).MakeGenericType(innerType),
110 obj.Unwrap(innerType, caller)
119 return Convert.ChangeType(num.Value, t);
120 case IBadNative native when t.IsAssignableFrom(native.Type):
124 if (t.GetArrayRank() != 1)
129 object[] sarr = arr.InnerArray.Select(x => x.Unwrap(t.GetElementType()!, caller))
131 Array rarr = Array.CreateInstance(t.GetElementType()!, arr.InnerArray.Count);
133 for (
int i = 0; i < sarr.Length; i++)
135 rarr.SetValue(sarr[i], i);
140 case BadArray arr when t.IsGenericType &&
141 (t.GetGenericTypeDefinition() == typeof(List<>) ||
142 t.GetGenericTypeDefinition() == typeof(IList<>)):
144 Type elemType = t.GetGenericArguments()[0];
145 IEnumerable<object> sarr = arr.InnerArray.Select(x => x.Unwrap(elemType, caller));
146 IList? rarr = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elemType));
148 foreach (
object o
in sarr)
180 if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(
BadNullable<>))
182 Type innerType = typeof(T).GetGenericArguments()[0];
186 return (T)Activator.CreateInstance(typeof(
BadNullable<>).MakeGenericType(innerType));
189 return (T)Activator.CreateInstance(typeof(
BadNullable<>).MakeGenericType(innerType),
190 obj.Unwrap(innerType, caller)
194 if (obj is
IBadString str && typeof(T) == typeof(
string))
196 return (T)(object)str.Value;
199 if (obj is
IBadNumber num && typeof(T).IsNumericType())
201 return (T)Convert.ChangeType(num.Value, typeof(T));
214 Type type = typeof(T);
218 if (type.GetArrayRank() != 1)
223 object[] sarr = arr.InnerArray.Select(x => x.Unwrap(type.GetElementType()!, caller))
225 Array rarr = Array.CreateInstance(type.GetElementType()!, arr.InnerArray.Count);
227 for (
int i = 0; i < sarr.Length; i++)
229 rarr.SetValue(sarr[i], i);
232 return (T)(object)rarr;
235 if (!type.IsGenericType ||
236 (type.GetGenericTypeDefinition() != typeof(List<>) &&
237 type.GetGenericTypeDefinition() != typeof(IList<>)))
242 Type elemType = type.GetGenericArguments()[0];
243 IEnumerable<object> suarr = arr.InnerArray.Select(x => x.Unwrap(elemType, caller));
244 IList? ruarr = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elemType));
246 foreach (
object o
in suarr)
261 if (!t.IsGenericType)
266 Type? gt = t.GetGenericTypeDefinition();
268 return gt == typeof(Func<>) ||
269 gt == typeof(Func<,>) ||
270 gt == typeof(Func<,,>) ||
271 gt == typeof(Func<,,,>) ||
272 gt == typeof(Func<,,,,>) ||
273 gt == typeof(Func<,,,,,>) ||
274 gt == typeof(Func<,,,,,,>) ||
275 gt == typeof(Func<,,,,,,,>) ||
276 gt == typeof(Func<,,,,,,,,>) ||
277 gt == typeof(Func<,,,,,,,,,>) ||
278 gt == typeof(Func<,,,,,,,,,,>) ||
279 gt == typeof(Func<,,,,,,,,,,,>) ||
280 gt == typeof(Func<,,,,,,,,,,,,>) ||
281 gt == typeof(Func<,,,,,,,,,,,,,>) ||
282 gt == typeof(Func<,,,,,,,,,,,,,,>) ||
283 gt == typeof(Func<,,,,,,,,,,,,,,,>) ||
284 gt == typeof(Func<,,,,,,,,,,,,,,,,>);
295 if (!t.IsGenericType)
297 return t == typeof(Action);
300 Type? gt = t.GetGenericTypeDefinition();
302 return gt == typeof(Action<>) ||
303 gt == typeof(Action<,>) ||
304 gt == typeof(Action<,,>) ||
305 gt == typeof(Action<,,,>) ||
306 gt == typeof(Action<,,,,>) ||
307 gt == typeof(Action<,,,,,>) ||
308 gt == typeof(Action<,,,,,,>) ||
309 gt == typeof(Action<,,,,,,,>) ||
310 gt == typeof(Action<,,,,,,,,>) ||
311 gt == typeof(Action<,,,,,,,,,>) ||
312 gt == typeof(Action<,,,,,,,,,,>) ||
313 gt == typeof(Action<,,,,,,,,,,,>) ||
314 gt == typeof(Action<,,,,,,,,,,,,>) ||
315 gt == typeof(Action<,,,,,,,,,,,,,>) ||
316 gt == typeof(Action<,,,,,,,,,,,,,,,>);