• <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中動態(tài)創(chuàng)建類型---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 悟山 閱讀(901) 評論(1)  編輯 收藏 引用

            Feedback

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

            偶遇留言  回復  更多評論   


            99久久免费国产特黄| 国产精品久久午夜夜伦鲁鲁| 久久久久亚洲精品无码网址 | 久久综合狠狠综合久久97色| 久久久高清免费视频| 国产精品视频久久| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久国产劲爆AV内射—百度| 久久国产精品久久久| 久久性生大片免费观看性| 久久久久亚洲AV无码网站| 日产久久强奸免费的看| 国产精品久久永久免费| 伊人久久大香线蕉av不卡| 久久精品二区| 国产成人综合久久精品尤物| 狠狠色综合网站久久久久久久高清 | 丁香久久婷婷国产午夜视频| 影音先锋女人AV鲁色资源网久久 | 亚洲国产精品综合久久网络| 久久免费美女视频| 中文精品久久久久人妻不卡| 亚洲日本va午夜中文字幕久久 | 久久精品成人免费网站| 无码人妻精品一区二区三区久久 | 国产69精品久久久久99| 久久国产乱子伦免费精品| 久久精品一本到99热免费| 欧美日韩成人精品久久久免费看| 国内精品久久久久久麻豆| 久久国产精品成人免费| av无码久久久久不卡免费网站| 日韩精品久久无码人妻中文字幕| 四虎影视久久久免费| 亚洲伊人久久成综合人影院 | 久久se精品一区二区影院| 亚洲成人精品久久| 久久国产影院| 久久人人爽人人爽人人片AV麻烦 | 日本一区精品久久久久影院| 国产精品天天影视久久综合网|