• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我生如山

            在.Net Framework中動態創建類型---System.Reflection.Emit命名空間小試

             string assemblyName = this.txtAssemblyName.Text;
                        
            string className = this.txtClassName.Text;

                        System.Diagnostics.Debug.Assert(assemblyName 
            != null && assemblyName != string.Empty);
                        System.Diagnostics.Debug.Assert(className 
            != null && className != string.Empty);

                        System.Reflection.AssemblyName asmName 
            = new System.Reflection.AssemblyName(assemblyName);
                        AssemblyBuilder asmBuilder 
            = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
                        ModuleBuilder modBuilder 
            = asmBuilder.DefineDynamicModule("MyModule"true);

                        TypeBuilder typeBuilder 
            = modBuilder.DefineType(className);
                        typeBuilder.DefineField(
            "myfield",typeof(string), System.Reflection.FieldAttributes.Public);
                        MethodBuilder methodBuilder 
            = typeBuilder.DefineMethod("CallMethod", System.Reflection.MethodAttributes.Public| System.Reflection.MethodAttributes.SpecialName | System.Reflection.MethodAttributes.HideBySig
                            
                            , 
            nullnew Type[] { typeof(string) });

                        methodBuilder.DefineParameter(
            0, System.Reflection.ParameterAttributes.Retval, null);
                        methodBuilder.DefineParameter(
            1, System.Reflection.ParameterAttributes.In, "name");
                        ILGenerator ilGenerator 
            = methodBuilder.GetILGenerator();

                        ilGenerator.Emit(OpCodes.Ldarg_1);
                        
            //System.Reflection.Assembly asmSystem = System.Reflection.Assembly.GetAssembly(typeof(MessageBox));
                        
            //Type typeMessageBox = asmSystem.GetType("MessageBox");
                        Type typeMessageBox = typeof(MessageBox);
                        System.Reflection.MethodInfo mInfoShow 
            = typeMessageBox.GetMethod("Show",new Type[]{typeof(string)}
                            
            //System.Reflection.BindingFlags.Public| System.Reflection.BindingFlags.Static,
                            );

                        ilGenerator.EmitCall(OpCodes.Call, mInfoShow, 
            null);

                        ilGenerator.Emit(OpCodes.Ret);

                        Type customType 
            = typeBuilder.CreateType();
                        
            object customeObj = Activator.CreateInstance(customType); ;

                        System.Reflection.MethodInfo methodInfo 
            = customType.GetMethod("CallMethod");
                        
            //customType.InvokeMember("CallMethod", System.Reflection.BindingFlags.Public, null, customeObj, new object[] { "123" });
                        
            //methodBuilder.Invoke(customeObj, new object[] { "123" });
                        methodInfo.Invoke(customeObj, new object[] { "11" });
                        Console.ReadLine();

            posted on 2009-07-24 21:51 悟山 閱讀(914) 評論(1)  編輯 收藏 引用

            Feedback

            # re: 在.Net Framework中動態創建類型---System.Reflection.Emit命名空間小試 2009-11-05 17:06 agri521

            偶遇留言  回復  更多評論   


            四虎国产精品免费久久5151| 久久久无码人妻精品无码| 久久久久中文字幕| 久久精品亚洲乱码伦伦中文 | 九九久久精品无码专区| 精品久久久久久久中文字幕| 久久人人爽人人爽人人片AV东京热| 狠狠色婷婷久久综合频道日韩 | 国产精品伊人久久伊人电影| 久久人人爽人人爽人人片AV不| 精品无码久久久久久尤物| 噜噜噜色噜噜噜久久| 国内精品伊人久久久久| 亚洲AV日韩精品久久久久| 久久性生大片免费观看性| WWW婷婷AV久久久影片| 三级三级久久三级久久| 久久精品中文字幕有码| 久久综合九色综合97_久久久| 欧洲成人午夜精品无码区久久| 亚洲另类欧美综合久久图片区| 国产一区二区精品久久凹凸| 久久97精品久久久久久久不卡| 人妻精品久久久久中文字幕一冢本| 日韩亚洲国产综合久久久| 色综合久久最新中文字幕| 精品久久久久久| 国产精品久久久久久搜索| 99久久无码一区人妻a黑| 久久一日本道色综合久久| 久久夜色精品国产欧美乱| 久久久久无码精品国产不卡| 香蕉久久夜色精品升级完成| 久久国产劲爆AV内射—百度| 国产成人精品三上悠亚久久| 久久精品国产免费观看三人同眠| 国产精品久久久久久久久软件| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 国产精品九九久久精品女同亚洲欧美日韩综合区| 国产激情久久久久久熟女老人| 久久中文字幕人妻丝袜|