Пример #1
0
        private Emit::DynamicMethod CreateDynamicMethod(string name)
        {
            if (!typeof(System.Delegate).IsAssignableFrom(typeof(D)))
            {
                throw new System.InvalidProgramException("DynamicMethodCreator の第二型引数はデリゲート型である必要があります。");
            }
            Ref::MethodInfo minfo = typeof(D).GetMethod("Invoke");

            // 引数の型
            Gen::List <System.Type> param_types = new System.Collections.Generic.List <System.Type>();

            if (!is_static)
            {
                param_types.Add(typeof(T));
            }
            foreach (Ref::ParameterInfo p in minfo.GetParameters())
            {
                param_types.Add(p.ParameterType);
            }

            return(new Emit::DynamicMethod(
                       typeof(T).FullName + "::" + name,
                       minfo.ReturnType, param_types.ToArray(), typeof(T)
                       ));
        }
Пример #2
0
 public static bool IsTestable(Ref::MethodInfo minfo)
 {
     Ref::ParameterInfo[] pinfos = minfo.GetParameters();
     if (pinfos.Length > 1)
     {
         return(false);
     }
     if (pinfos.Length == 1)
     {
         return(pinfos[0].ParameterType == typeof(afh.Application.Log));
     }
     return(false);
 }
Пример #3
0
        public static void testComposedType(afh.Application.Log log)
        {
            System.Action <System.Type> write = delegate(System.Type t){
                testComposedType_write(t, log);
            };

            Ref::MethodInfo minfo = typeof(UnitTest).GetMethod("testComposedType_meth", Ref::BindingFlags.Static | Ref::BindingFlags.NonPublic);

            Ref::ParameterInfo[] pinfos = minfo.GetParameters();
            log.Lock();
            write(typeof(int *));
            write(pinfos[0].ParameterType);
            write(pinfos[1].ParameterType);
            write(pinfos[2].ParameterType);
            log.Unlock();

            Ref::MethodInfo minfo2 = pinfos[2].ParameterType.GetMethod("Method", Ref::BindingFlags.Static | Ref::BindingFlags.Public);

            log.WriteLine(Types.GetMethodSignature(minfo));
            log.WriteLine(Types.GetMethodSignature(minfo2));
        }
Пример #4
0
        //===========================================================
        //		初期化
        //===========================================================
        public static BenchMethodAttribute GetAttribute(Ref::MethodInfo minfo, afh.Application.Log log)
        {
            object[] attrs = minfo.GetCustomAttributes(typeof(BenchMethodAttribute), false);
            if (attrs.Length == 0)
            {
                return(null);
            }

            BenchMethodAttribute attr = (BenchMethodAttribute)attrs[0];

            if (!minfo.IsStatic)
            {
                log.WriteLine("メソッド '{0}' は static でない為 Benchmark を実行出来ません。", minfo);
                return(null);
            }
            if (minfo.GetParameters().Length != 0)
            {
                log.WriteLine("メソッド '{0}' の呼び出しには引数が必要なので Benchmark を実行出来ません。", minfo);
                return(null);
            }
            return(attr);
        }