-
Notifications
You must be signed in to change notification settings - Fork 4
/
Utils.cs
22 lines (20 loc) · 972 Bytes
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using HarmonyLib;
using System;
using System.Linq;
using System.Reflection;
namespace DrakiaXYZ.BigBrain
{
internal class Utils
{
public static FieldInfo GetFieldByType(Type classType, Type fieldType)
{
return AccessTools.GetDeclaredFields(classType).FirstOrDefault(
x => fieldType.IsAssignableFrom(x.FieldType) || (x.FieldType.IsGenericType && fieldType.IsGenericType && fieldType.GetGenericTypeDefinition().IsAssignableFrom(x.FieldType.GetGenericTypeDefinition())));
}
public static string GetPropertyNameByType(Type classType, Type propertyType)
{
return AccessTools.GetDeclaredProperties(classType).FirstOrDefault(
x => propertyType.IsAssignableFrom(x.PropertyType) || (x.PropertyType.IsGenericType && propertyType.IsGenericType && propertyType.GetGenericTypeDefinition().IsAssignableFrom(x.PropertyType.GetGenericTypeDefinition())))?.Name;
}
}
}