public static object Invoke(Type type, string name, object item, params object[] parameters) { var types = new Type[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { types[i] = parameters[i]?.GetType() ?? typeof(object); } return Invoke((MethodInfo)TypeHelper.GetMemberInfo(type, name, out _, false, types), item, parameters); }
public static IInvoker Initialize(MemberInfo info, bool cache, object index = null) { if (info == null) return null; var token = MetadataToken.GetToken(info); if (cache) { if (cacheInvokers.TryGetValue(token, out var invoker)) { return invoker; } var baseInfo = info.GetMemberBaseDefinition(); var baseToken = MetadataToken.GetToken(baseInfo); if (cacheInvokers.TryGetValue(baseToken, out invoker)) { return invoker; } if (baseInfo.DeclaringType.IsGenericType && !baseInfo.DeclaringType.IsGenericTypeDefinition) { var genericType = baseInfo.DeclaringType.GetGenericTypeDefinition(); var genericInfo = TypeHelper.GetMemberInfo(genericType, baseInfo.Name, out index, false); var genericToken = MetadataToken.GetToken(genericInfo); if (cacheGenericInvokers.TryGetValue(genericToken, out var genericInvokerType)) { var type = genericInvokerType.MakeGenericType(info.DeclaringType.GetGenericArguments()); return CacheInvokers(token, (IInvoker)Activator.CreateInstance(type), info); } } else if (cacheGenericInvokers.TryGetValue(baseToken, out var genericInvokerType)) { var type = genericInvokerType.MakeGenericType(info.DeclaringType); return CacheInvokers(token, (IInvoker)Activator.CreateInstance(type), info); } } return CacheInvokers(token, Initialize(info, index), info); }
public static void RegisterInvoker(Type type, string memberName, IInvoker invoker) { RegisterInvoker(TypeHelper.GetMemberInfo(type, memberName, out _, false), invoker); }
public static void SetValue(Type type, string name, object item, object value) { SetValue(TypeHelper.GetMemberInfo(type, name, out _, false), item, value); }
public static object GetValue(Type type, string name, object item) { return GetValue(TypeHelper.GetMemberInfo(type, name, out _, false), item); }
static EmitInvoker() { var methoInfo = TypeHelper.GetMemberInfo(typeof(object), nameof(ToString), out _, false); cacheInvokers[MetadataToken.GetToken(methoInfo)] = ToStringInvoker<object>.Instance; }
static EmitInvoker() { var methoInfo = TypeHelper.GetMemberInfo(typeof(object), nameof(ToString)); cacheInvokers[GetToken(methoInfo)] = ToStringInvoker.Instance; }
public PropertyInvoker(string name) : this((PropertyInfo)TypeHelper.GetMemberInfo(typeof(T), name, out _, false)) { }
public static IndexPropertyInvoker <T, V, K> Create(string name) { var property = (PropertyInfo)TypeHelper.GetMemberInfo(typeof(T), name, out var index, false); return(new IndexPropertyInvoker <T, V, K>(property, index)); }
public FieldInvoker(string name) : this((FieldInfo)TypeHelper.GetMemberInfo(typeof(T), name)) { }