static ReflectionDelegates() { var type = typeof(Type); GetProperties = (GetTypeProperties)Delegate.CreateDelegate(typeof(GetTypeProperties), type.GetMethod("GetProperties")); GetCustomAttributes = (GetTypeCustomAttributes)Delegate.CreateDelegate(typeof(GetTypeCustomAttributes), type.GetMethod("GetCustomAttributes")); GetCustomAttribute = (GetTypeAttribute)Delegate.CreateDelegate(typeof(GetTypeAttribute), type.GetMethod("GetCustomAttribute")); GetMethod = (GetTypeMethod)Delegate.CreateDelegate(typeof(GetTypeMethod), type.GetMethod("GetMethod")); GetConstructors = (GetTypeConstructors)Delegate.CreateDelegate(typeof(GetTypeConstructors), type.GetMethod("GetConstructors")); }
public static NbtType GetNbtType(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var nbtType = TypeMap.GetOrAdd(type, (t) => { var obj = GetTypeMethod.MakeGenericMethod(t).Invoke(null, null); return((NbtType)obj !); }); return(nbtType); }