Example #1
0
        public static Ref::MethodInfo LoadMethod(string file, string className, string methodName, string[] paramTypes)
        {
            // TODO: 色々な場所の候補
            System.Type type = LoadType(file, className);
            if (type == null)
            {
                throw new System.Exception("指定した型は見つかりません。");
            }

            // メソッドの検索
            Ref::BindingFlags BF = Ref::BindingFlags.NonPublic | Ref::BindingFlags.Public | Ref::BindingFlags.Static;

            System.Type[] tParamTypes = new System.Type[paramTypes.Length];
            for (int i = 0; i < paramTypes.Length; i++)
            {
                System.Type tParam = NameToPrimitiveType(paramTypes[i]);
                if (tParam == null)
                {
                    throw new System.FormatException("関数の引数型を認識できません。");
                }
            }

            Ref::MethodInfo m = type.GetMethod(methodName, BF, null, tParamTypes, null);

            if (m == null)
            {
                throw new System.MissingMethodException("指定されたメソッドは見つかりません。");
            }

            return(m);
        }
Example #2
0
        public override ICustomWriter GetCustomWriter(System.Type type)
        {
            const Ref::BindingFlags BF           = Ref::BindingFlags.Public | Ref::BindingFlags.NonPublic | Ref::BindingFlags.Instance;
            const string            MISSING_CTOR = @"[BindCustomWriterAttribute({0})]
指定した ICustomWriter 実装型{0}には、System.Type 一つを引数に持つコンストラクタ亦は、既定のコンストラクタが定義されていません。
.ctor(System.Type) / .ctor() の何れかが実装されている必要があります。詳細に関しては BindCustomWriterAttribute の説明で確認して下さい。";

            //-------------------------------------------------------
            if (writer != null)
            {
                return(writer);
            }

            Ref::ConstructorInfo ctor;

            ctor = writer_type.GetConstructor(BF, null, new System.Type[] { typeof(System.Type) }, null);
            if (ctor != null)
            {
                return(this.writer = (ICustomWriter)ctor.Invoke(new object[] { type }));
            }
            ctor = writer_type.GetConstructor(BF, null, new System.Type[0], null);
            if (ctor != null)
            {
                return(this.writer = (ICustomWriter)ctor.Invoke(new object[0]));
            }

            throw new System.MissingMethodException(string.Format(MISSING_CTOR, writer_type));
        }
Example #3
0
            public Reader(CustomReadAttribute attr, System.Type type)
            {
                const Ref::BindingFlags BF = Ref::BindingFlags.Public | Ref::BindingFlags.NonPublic | Ref::BindingFlags.Static;

                this.info = (Ref::MethodInfo)GetMemberInfo(type, attr.method, BF, InvokingFlags.Method_ParamAccessor);
                this.type = type;
            }
Example #4
0
        private void ReadType(System.Type type)
        {
            const Ref::BindingFlags BF = Ref::BindingFlags.Static | Ref::BindingFlags.Public | Ref::BindingFlags.NonPublic;

            afh.Application.Log log = Program.log;

            log.WriteLine("ReadType: {0}", type.FullName);
            foreach (Ref::MethodInfo minfo in type.GetMethods(BF))
            {
                // 超いい加減引数チェック
                if (TestMethod.IsTestable(minfo))
                {
                    TestMethod test = new TestMethod(minfo);
                    test.WriteSummary(log);
                    this.listBox1.Items.Add(test);
                }

                BenchMethodAttribute benchattr = BenchMethod.GetAttribute(minfo, log);
                if (benchattr != null)
                {
                    BenchMethod bench = new BenchMethod(minfo, benchattr);
                    this.listBox1.Items.Add(bench);
                }
            }
        }
Example #5
0
        /// <summary>
        /// 指定したフィールドの値を取得します。
        /// </summary>
        /// <param name="type">フィールドを保持している型を指定します。</param>
        /// <param name="fieldName">フィールドの名前を指定します。</param>
        /// <param name="is_static">静的フィールドか否かを指定します。</param>
        /// <param name="is_private">非公開メンバか否かを指定します。</param>
        public void EmitLdfld(System.Type type, string fieldName, bool is_static, bool is_private)
        {
            Ref::BindingFlags BINDING
                = (is_private?Ref::BindingFlags.NonPublic:Ref::BindingFlags.Public)
                  | (is_static?Ref::BindingFlags.Static:Ref::BindingFlags.Instance);
            Ref::FieldInfo finfo = type.GetField(fieldName, BINDING);

            gen.Emit(Emit::OpCodes.Ldfld, finfo);
        }
Example #6
0
        public override void Write(object value, StreamAccessor accessor)
        {
            const Ref::BindingFlags BF   = Ref::BindingFlags.Public | Ref::BindingFlags.NonPublic | Ref::BindingFlags.Static;
            Ref::MethodInfo         info = (Ref::MethodInfo)GetMemberInfo(value.GetType(), this.method, BF, InvokingFlags.Method_ParamObjectAccessor);

            try{
                info.Invoke(null, new object[] { value, accessor });
            }catch (System.Exception e) {
                __dll__.log.WriteError(e, "独自定義ストリーム書込で例外が発生しました。");
                throw;
            }
        }
Example #7
0
        private void Force0x20_0()
        {
            Ref::BindingFlags BF = Ref::BindingFlags.Instance | Ref::BindingFlags.NonPublic;

            System.Type ptype = typeof(System.Windows.Forms.PictureBox);

            Ref::FieldInfo fstate = ptype.GetField("pictureBoxState", BF);

            System.Collections.Specialized.BitVector32 vec = (System.Collections.Specialized.BitVector32)fstate.GetValue(this);
            vec[0x20] = false;
            fstate.SetValue(this, vec);
        }
Example #8
0
        private void SaveStatus()
        {
            Ref::BindingFlags BF = Ref::BindingFlags.Instance | Ref::BindingFlags.NonPublic;

            System.Type ptype = typeof(System.Windows.Forms.PictureBox);
            this.status = new Gen::Dictionary <Ref::FieldInfo, object>();

            foreach (Ref::FieldInfo finfo in ptype.GetFields(BF))
            {
                this.status.Add(finfo, finfo.GetValue(this));
            }
        }
Example #9
0
        /// <summary>
        /// 仮想関数呼び出しを出力します。
        /// </summary>
        /// <param name="type">仮想メソッドが宣言されているクラスを指定します。</param>
        /// <param name="is_private">仮想メソッドが private/internal であるか否かを指定します。</param>
        /// <param name="is_static">静的メソッドであるか否かを指定します。</param>
        /// <param name="methodName">仮想メソッドの名前を指定します。</param>
        /// <param name="param_types">仮想メソッドの引数の型を指定します。</param>
        public void EmitCallvirt(
            System.Type type, bool is_private, bool is_static,
            string methodName, params System.Type[] param_types
            )
        {
            Ref::BindingFlags BINDING
                = (is_private?Ref::BindingFlags.NonPublic:Ref::BindingFlags.Public)
                  | (is_static?Ref::BindingFlags.Static:Ref::BindingFlags.Instance);
            Ref::MethodInfo method = type.GetMethod(methodName, BINDING, null, param_types, null);

            gen.Emit(Emit::OpCodes.Callvirt, method);
        }
Example #10
0
 protected override void WndProc(ref System.Windows.Forms.Message m)
 {
     try{
         base.WndProc(ref m);
     }catch (System.Runtime.InteropServices.ExternalException xe) {
         if (!this.DesignMode)
         {
             Program.log.WriteError(xe);
         }
         Ref::BindingFlags BF = Ref::BindingFlags.Instance | Ref::BindingFlags.NonPublic;
         typeof(System.Windows.Forms.Control).GetMethod("SetState", BF).Invoke(this, new object[] { 0x400000, false });
     }
 }
Example #11
0
        public static Ref::MethodInfo LoadMethod(string file, string className, string methodName, int numOfParams)
        {
            // TODO: 色々な場所の候補
            System.Type type = LoadType(file, className);
            if (type == null)
            {
                throw new System.Exception("指定した型は見つかりません。");
            }

            // メソッドの検索
            Ref::BindingFlags BF = Ref::BindingFlags.NonPublic | Ref::BindingFlags.Public | Ref::BindingFlags.Static;
            Ref::MethodInfo   m  = null;

            foreach (Ref::MethodInfo minfo in type.GetMethods(BF))
            {
                if (minfo.Name != methodName)
                {
                    continue;
                }

                // 引数型を check
                Ref::ParameterInfo[] pinfos = minfo.GetParameters();
                int i;
                for (i = 0; i < pinfos.Length; i++)
                {
                    if (!IsPrimitive(pinfos[i].ParameterType))
                    {
                        break;
                    }
                }
                if (i != pinfos.Length)
                {
                    continue;
                }

                if (m != null)
                {
                    throw new System.Reflection.AmbiguousMatchException("オーバーロードを特定できません。");
                }

                m = minfo;
            }

            if (m == null)
            {
                throw new System.MissingMethodException("指定されたメソッドは見つかりません。");
            }

            return(m);
        }
Example #12
0
    public static void analyze_generic_PrimitiveTypes(afh.Application.Log log)
    {
        const Ref::BindingFlags BF       = Ref::BindingFlags.Static | Ref::BindingFlags.NonPublic;
        Ref::MethodInfo         gen_meth = typeof(UnitTest).GetMethod("analyze_genprim_IsLargerThan", BF);
        Ref::MethodInfo         nrm_meth = typeof(UnitTest).GetMethod("analyze_genprim_IsLargerThanPrim", BF);

        log.WriteLine("generic<T> body");
        log.DumpBytes(gen_meth.GetMethodBody().GetILAsByteArray());         // null らしい
        log.WriteLine("generic<int> body");
        log.DumpBytes(gen_meth.MakeGenericMethod(typeof(int)).GetMethodBody().GetILAsByteArray());
        log.WriteLine("normal body");
        log.DumpBytes(nrm_meth.GetMethodBody().GetILAsByteArray());

        // 実際に実験
        log.WriteLine(analyze_genprim_IsLargerThan <int>(10, 8));
        log.WriteLine(analyze_genprim_IsLargerThanPrim(10, 8));
    }
Example #13
0
        public override object Read(System.Type type, StreamAccessor accessor)
        {
            const Ref::BindingFlags BF   = Ref::BindingFlags.Public | Ref::BindingFlags.NonPublic | Ref::BindingFlags.Static;
            Ref::MethodInfo         info = (Ref::MethodInfo)GetMemberInfo(type, this.method, BF, InvokingFlags.Method_ParamAccessor);
            object ret;

            try{
                ret = info.Invoke(null, new object[] { accessor });
            }catch (System.Exception e) {
                __dll__.log.WriteError(e, "独自定義ストリーム読込で例外が発生しました。");
                throw;
            }
            if (!type.IsInstanceOfType(ret))
            {
                throw new System.InvalidCastException();
            }
            return(ret);
        }
Example #14
0
 protected override void WndProc(ref System.Windows.Forms.Message m)
 {
     try{
         if (m.Msg == 0xf && this.Image != null && gdi_erred)
         {
             //gdi_erred=false;
             //this.Force0x20_0();
         }
         base.WndProc(ref m);
         if (m.Msg == 0xf && this.Image != null)
         {
             result = m.Result;
             //this.SaveStatus();
         }
     }catch (System.Runtime.InteropServices.ExternalException xe) {
         Program.log.WriteError(xe);
         Ref::BindingFlags BF = Ref::BindingFlags.Instance | Ref::BindingFlags.NonPublic;
         typeof(System.Windows.Forms.Control).GetMethod("SetState", BF).Invoke(this, new object[] { 0x400000, false });
         this.gdi_erred = true;
     }
 }
Example #15
0
        /// <summary>
        /// 読み書きに使用するメンバ情報を取得します。
        /// </summary>
        /// <param name="type">メンバを保持する型を指定します。</param>
        /// <param name="member">メンバ名を指定します。</param>
        /// <param name="bindings">検索するメンバのバインドの形態を指定します。</param>
        /// <param name="flags">検索するメンバの種類を指定します。</param>
        /// <returns>見つかったメンバの情報を返します。</returns>
        /// <exception cref="System.Reflection.AmbiguousMatchException">
        /// 適合するメンバが複数見つかった場合に発生します。
        /// </exception>
        /// <exception cref="System.MissingFieldException">
        /// 適合するメンバ (フィールドに限らない) が見つからなかった場合に発生します。
        /// </exception>
        protected static System.Reflection.MemberInfo GetMemberInfo(System.Type type, string member, Ref::BindingFlags bindings, InvokingFlags flags)
        {
            const System.Reflection.MemberTypes MT
                = System.Reflection.MemberTypes.Field
                  | System.Reflection.MemberTypes.Property
                  | System.Reflection.MemberTypes.Method;

            System.Reflection.MemberInfo[] infos = type.GetMember(member, MT, bindings);
            bool found = false;

            System.Reflection.MemberInfo ret = null;
            for (int i = 0; i < infos.Length; i++)
            {
                switch (infos[i].MemberType)
                {
                case System.Reflection.MemberTypes.Field:
                    if ((flags & InvokingFlags.Field) != 0)
                    {
                        goto regist;
                    }
                    break;

                case System.Reflection.MemberTypes.Property:
                    if ((flags & InvokingFlags.PropertyNoIndexParameter) != 0 &&
                        ((System.Reflection.PropertyInfo)infos[i]).GetIndexParameters().Length == 0)
                    {
                        goto regist;
                    }
                    break;

                case System.Reflection.MemberTypes.Method:
                    System.Reflection.ParameterInfo[] pinfos = ((System.Reflection.MethodInfo)infos[i]).GetParameters();
                    if ((flags & InvokingFlags.Method_NoParameter) != 0 && pinfos.Length == 0)
                    {
                        goto regist;
                    }
                    if ((flags & InvokingFlags.Method_ParamAccessor) != 0 &&
                        pinfos.Length == 1 &&
                        pinfos[0].ParameterType.IsAssignableFrom(typeof(StreamAccessor)))
                    {
                        goto regist;
                    }
                    if ((flags & InvokingFlags.Method_ParamObjectAccessor) != 0 &&
                        pinfos.Length == 2 &&
                        pinfos[1].ParameterType.IsAssignableFrom(typeof(StreamAccessor)))
                    {
                        goto regist;
                    }
                    break;
regist:
                    if (found)
                    {
                        throw new System.Reflection.AmbiguousMatchException();
                    }
                    found = true;
                    ret   = infos[i];
                    break;
                }
            }
            if (!found)
            {
                throw new System.MissingFieldException(type.FullName, member);
            }
            return(ret);
        }