Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 public static void RegisterInvoker(Type type, string memberName, IInvoker invoker)
 {
     RegisterInvoker(TypeHelper.GetMemberInfo(type, memberName, out _, false), invoker);
 }
Exemple #4
0
 public static void SetValue(Type type, string name, object item, object value)
 {
     SetValue(TypeHelper.GetMemberInfo(type, name, out _, false), item, value);
 }
Exemple #5
0
 public static object GetValue(Type type, string name, object item)
 {
     return GetValue(TypeHelper.GetMemberInfo(type, name, out _, false), item);
 }
Exemple #6
0
 static EmitInvoker()
 {
     var methoInfo = TypeHelper.GetMemberInfo(typeof(object), nameof(ToString), out _, false);
     cacheInvokers[MetadataToken.GetToken(methoInfo)] = ToStringInvoker<object>.Instance;
 }
Exemple #7
0
        static EmitInvoker()
        {
            var methoInfo = TypeHelper.GetMemberInfo(typeof(object), nameof(ToString));

            cacheInvokers[GetToken(methoInfo)] = ToStringInvoker.Instance;
        }
Exemple #8
0
 public PropertyInvoker(string name)
     : this((PropertyInfo)TypeHelper.GetMemberInfo(typeof(T), name, out _, false))
 {
 }
Exemple #9
0
        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));
        }
Exemple #10
0
 public FieldInvoker(string name)
     : this((FieldInfo)TypeHelper.GetMemberInfo(typeof(T), name))
 {
 }