69 Type oType = obj.GetType();
71 if (t.IsAssignableFrom(oType))
76 if (oType.IsGenericType && oType.GetGenericTypeDefinition() == typeof(
BadNullable<>))
78 Type innerType = oType.GetGenericArguments()[0];
82 return Activator.CreateInstance(typeof(
BadNullable<>).MakeGenericType(innerType));
85 return Activator.CreateInstance(
87 obj.Unwrap(innerType, caller)
96 return Convert.ChangeType(num.Value, t);
97 case IBadNative native when t.IsAssignableFrom(native.Type):
101 if (t.GetArrayRank() != 1)
106 object[] sarr = arr.InnerArray.Select(x => x.Unwrap(t.GetElementType()!, caller)).ToArray();
107 Array rarr = Array.CreateInstance(t.GetElementType()!, arr.InnerArray.Count);
109 for (
int i = 0; i < sarr.Length; i++)
111 rarr.SetValue(sarr[i], i);
116 case BadArray arr when t.IsGenericType &&
117 (t.GetGenericTypeDefinition() == typeof(List<>) || t.GetGenericTypeDefinition() == typeof(IList<>)):
119 Type elemType = t.GetGenericArguments()[0];
120 IEnumerable<object> sarr = arr.InnerArray.Select(x => x.Unwrap(elemType, caller));
121 IList? rarr = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elemType));
123 foreach (
object o
in sarr)
156 if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(
BadNullable<>))
158 Type innerType = typeof(T).GetGenericArguments()[0];
162 return (T)Activator.CreateInstance(typeof(
BadNullable<>).MakeGenericType(innerType));
165 return (T)Activator.CreateInstance(
167 obj.Unwrap(innerType, caller)
171 if (obj is
IBadString str && typeof(T) == typeof(
string))
173 return (T)(object)str.Value;
176 if (obj is
IBadNumber num && typeof(T).IsNumericType())
178 return (T)Convert.ChangeType(num.Value, typeof(T));
191 Type type = typeof(T);
195 if (type.GetArrayRank() != 1)
200 object[] sarr = arr.InnerArray.Select(x => x.Unwrap(type.GetElementType()!, caller)).ToArray();
201 Array rarr = Array.CreateInstance(type.GetElementType()!, arr.InnerArray.Count);
203 for (
int i = 0; i < sarr.Length; i++)
205 rarr.SetValue(sarr[i], i);
208 return (T)(object)rarr;
211 if (!type.IsGenericType ||
212 type.GetGenericTypeDefinition() != typeof(List<>) &&
213 type.GetGenericTypeDefinition() != typeof(IList<>))
218 Type elemType = type.GetGenericArguments()[0];
219 IEnumerable<object> suarr = arr.InnerArray.Select(x => x.Unwrap(elemType, caller));
220 IList? ruarr = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elemType));
222 foreach (
object o
in suarr)
237 if (!t.IsGenericType)
242 Type? gt = t.GetGenericTypeDefinition();
244 return gt == typeof(Func<>) ||
245 gt == typeof(Func<,>) ||
246 gt == typeof(Func<,,>) ||
247 gt == typeof(Func<,,,>) ||
248 gt == typeof(Func<,,,,>) ||
249 gt == typeof(Func<,,,,,>) ||
250 gt == typeof(Func<,,,,,,>) ||
251 gt == typeof(Func<,,,,,,,>) ||
252 gt == typeof(Func<,,,,,,,,>) ||
253 gt == typeof(Func<,,,,,,,,,>) ||
254 gt == typeof(Func<,,,,,,,,,,>) ||
255 gt == typeof(Func<,,,,,,,,,,,>) ||
256 gt == typeof(Func<,,,,,,,,,,,,>) ||
257 gt == typeof(Func<,,,,,,,,,,,,,>) ||
258 gt == typeof(Func<,,,,,,,,,,,,,,>) ||
259 gt == typeof(Func<,,,,,,,,,,,,,,,>) ||
260 gt == typeof(Func<,,,,,,,,,,,,,,,,>);
271 if (!t.IsGenericType)
273 return t == typeof(Action);
276 Type? gt = t.GetGenericTypeDefinition();
278 return gt == typeof(Action<>) ||
279 gt == typeof(Action<,>) ||
280 gt == typeof(Action<,,>) ||
281 gt == typeof(Action<,,,>) ||
282 gt == typeof(Action<,,,,>) ||
283 gt == typeof(Action<,,,,,>) ||
284 gt == typeof(Action<,,,,,,>) ||
285 gt == typeof(Action<,,,,,,,>) ||
286 gt == typeof(Action<,,,,,,,,>) ||
287 gt == typeof(Action<,,,,,,,,,>) ||
288 gt == typeof(Action<,,,,,,,,,,>) ||
289 gt == typeof(Action<,,,,,,,,,,,>) ||
290 gt == typeof(Action<,,,,,,,,,,,,>) ||
291 gt == typeof(Action<,,,,,,,,,,,,,>) ||
292 gt == typeof(Action<,,,,,,,,,,,,,,,>);