コード例 #1
0
ファイル: CallSite.cs プロジェクト: viktorius/Viktor
        public static CallSite Create(MethodInfo info, ushort id, CallSiteCache cache)
        {
            Type[] args       = new Type[7];
            var    parameters = info.GetParameters();
            int    i          = 0;

            if (!info.IsStatic)
            {
                args[i] = info.DeclaringType;
                i++;
            }
            for (int x = 0; x < parameters.Length; x++, i++)
            {
                args[i] = parameters[x].ParameterType;
            }
            for (; i < args.Length; i++)
            {
                args[i] = typeof(DBNull);
            }
            var type   = typeof(CallSite <, , , , , ,>).MakeGenericType(args);
            var result = (CallSite)Activator.CreateInstance(type);

            result.Arguments = args;
            result.Build(info, id, cache);
            return(result);
        }
コード例 #2
0
        public override void Build(MethodInfo info, ushort id, CallSiteCache cache)
        {
            Id         = id;
            MethodInfo = info;

            Serializer1 = cache.GetSerializer <T1>();
            Serializer2 = cache.GetSerializer <T2>();
            Serializer3 = cache.GetSerializer <T3>();
            Serializer4 = cache.GetSerializer <T4>();
            Serializer5 = cache.GetSerializer <T5>();
            Serializer6 = cache.GetSerializer <T6>();
            Serializer7 = cache.GetSerializer <T7>();

            // TODO: Target
            //SerializerTarget = cache.GetSerializer(MethodInfo);

            var p = Arguments.Select(s => Expression.Parameter(s)).ToArray();

            Expression call;

            if (info.IsStatic)
            {
                call = Expression.Call(info, p.Where(s => s.Type != typeof(DBNull)).ToArray());
            }
            else
            {
                call = Expression.Call(p.First(), info, p.Skip(1).Where(s => s.Type != typeof(DBNull)).ToArray());
                //call = Expression.Call(fieldEx.First(), info, fieldEx.Skip(1).ToArray());
            }
            Handler = Expression.Lambda <Action <T1, T2, T3, T4, T5, T6, T7> >(call, p).Compile();
        }
コード例 #3
0
ファイル: CallSite.cs プロジェクト: viktorius/Viktor
 public abstract void Build(MethodInfo info, ushort id, CallSiteCache cache);