139 lines
4.3 KiB
C#
139 lines
4.3 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace System.Linq.Expressions
|
|
{
|
|
// Token: 0x02000021 RID: 33
|
|
internal static class Extensions
|
|
{
|
|
// Token: 0x060001FE RID: 510 RVA: 0x0000B56C File Offset: 0x0000976C
|
|
public static bool IsGenericInstanceOf(this Type self, Type type)
|
|
{
|
|
return self.IsGenericType && self.GetGenericTypeDefinition() == type;
|
|
}
|
|
|
|
// Token: 0x060001FF RID: 511 RVA: 0x0000B584 File Offset: 0x00009784
|
|
public static bool IsNullable(this Type self)
|
|
{
|
|
return self.IsValueType && self.IsGenericInstanceOf(typeof(Nullable<>));
|
|
}
|
|
|
|
// Token: 0x06000200 RID: 512 RVA: 0x0000B5A4 File Offset: 0x000097A4
|
|
public static bool IsExpression(this Type self)
|
|
{
|
|
return self == typeof(Expression) || self.IsSubclassOf(typeof(Expression));
|
|
}
|
|
|
|
// Token: 0x06000201 RID: 513 RVA: 0x0000B5CC File Offset: 0x000097CC
|
|
public static bool IsGenericImplementationOf(this Type self, Type type)
|
|
{
|
|
foreach (Type type2 in self.GetInterfaces())
|
|
{
|
|
if (type2.IsGenericInstanceOf(type))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x06000202 RID: 514 RVA: 0x0000B608 File Offset: 0x00009808
|
|
public static bool IsAssignableTo(this Type self, Type type)
|
|
{
|
|
return type.IsAssignableFrom(self) || Extensions.ArrayTypeIsAssignableTo(self, type);
|
|
}
|
|
|
|
// Token: 0x06000203 RID: 515 RVA: 0x0000B620 File Offset: 0x00009820
|
|
public static Type GetFirstGenericArgument(this Type self)
|
|
{
|
|
return self.GetGenericArguments()[0];
|
|
}
|
|
|
|
// Token: 0x06000204 RID: 516 RVA: 0x0000B62C File Offset: 0x0000982C
|
|
public static Type MakeGenericTypeFrom(this Type self, Type type)
|
|
{
|
|
return self.MakeGenericType(type.GetGenericArguments());
|
|
}
|
|
|
|
// Token: 0x06000205 RID: 517 RVA: 0x0000B63C File Offset: 0x0000983C
|
|
public static Type MakeNullableType(this Type self)
|
|
{
|
|
return typeof(Nullable<>).MakeGenericType(new Type[] { self });
|
|
}
|
|
|
|
// Token: 0x06000206 RID: 518 RVA: 0x0000B658 File Offset: 0x00009858
|
|
public static Type GetNotNullableType(this Type self)
|
|
{
|
|
return (!self.IsNullable()) ? self : self.GetFirstGenericArgument();
|
|
}
|
|
|
|
// Token: 0x06000207 RID: 519 RVA: 0x0000B674 File Offset: 0x00009874
|
|
public static MethodInfo GetInvokeMethod(this Type self)
|
|
{
|
|
return self.GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public);
|
|
}
|
|
|
|
// Token: 0x06000208 RID: 520 RVA: 0x0000B684 File Offset: 0x00009884
|
|
public static MethodInfo MakeGenericMethodFrom(this MethodInfo self, MethodInfo method)
|
|
{
|
|
return self.MakeGenericMethod(method.GetGenericArguments());
|
|
}
|
|
|
|
// Token: 0x06000209 RID: 521 RVA: 0x0000B694 File Offset: 0x00009894
|
|
public static Type[] GetParameterTypes(this MethodBase self)
|
|
{
|
|
ParameterInfo[] parameters = self.GetParameters();
|
|
Type[] array = new Type[parameters.Length];
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i] = parameters[i].ParameterType;
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x0600020A RID: 522 RVA: 0x0000B6D4 File Offset: 0x000098D4
|
|
private static bool ArrayTypeIsAssignableTo(Type type, Type candidate)
|
|
{
|
|
return type.IsArray && candidate.IsArray && type.GetArrayRank() == candidate.GetArrayRank() && type.GetElementType().IsAssignableTo(candidate.GetElementType());
|
|
}
|
|
|
|
// Token: 0x0600020B RID: 523 RVA: 0x0000B720 File Offset: 0x00009920
|
|
public static void OnFieldOrProperty(this MemberInfo self, Action<FieldInfo> onfield, Action<PropertyInfo> onprop)
|
|
{
|
|
MemberTypes memberType = self.MemberType;
|
|
if (memberType == MemberTypes.Field)
|
|
{
|
|
onfield((FieldInfo)self);
|
|
return;
|
|
}
|
|
if (memberType != MemberTypes.Property)
|
|
{
|
|
throw new ArgumentException();
|
|
}
|
|
onprop((PropertyInfo)self);
|
|
}
|
|
|
|
// Token: 0x0600020C RID: 524 RVA: 0x0000B768 File Offset: 0x00009968
|
|
public static T OnFieldOrProperty<T>(this MemberInfo self, Func<FieldInfo, T> onfield, Func<PropertyInfo, T> onprop)
|
|
{
|
|
MemberTypes memberType = self.MemberType;
|
|
if (memberType == MemberTypes.Field)
|
|
{
|
|
return onfield((FieldInfo)self);
|
|
}
|
|
if (memberType != MemberTypes.Property)
|
|
{
|
|
throw new ArgumentException();
|
|
}
|
|
return onprop((PropertyInfo)self);
|
|
}
|
|
|
|
// Token: 0x0600020D RID: 525 RVA: 0x0000B7B0 File Offset: 0x000099B0
|
|
public static Type MakeStrongBoxType(this Type self)
|
|
{
|
|
return typeof(StrongBox<>).MakeGenericType(new Type[] { self });
|
|
}
|
|
}
|
|
}
|