• <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

            偶遇留言  回復  更多評論   


            无码任你躁久久久久久老妇App| 久久久久国产亚洲AV麻豆| 久久久精品无码专区不卡| 久久久久久亚洲精品无码| 狠狠色综合久久久久尤物| 蜜臀av性久久久久蜜臀aⅴ| 色偷偷888欧美精品久久久| 久久99精品国产麻豆蜜芽| 久久亚洲私人国产精品vA| 精品久久久久久国产免费了| 久久久久一本毛久久久| 久久精品国产亚洲网站| 成人妇女免费播放久久久| 热99RE久久精品这里都是精品免费| 国产亚洲精品自在久久| 国产精品无码久久综合| 狠狠88综合久久久久综合网| 亚洲国产视频久久| 麻豆精品久久久久久久99蜜桃| 狠狠综合久久综合中文88| 久久国产免费直播| 香蕉99久久国产综合精品宅男自 | 国产日韩久久免费影院| 久久久久亚洲精品无码网址| 国产2021久久精品| 国产69精品久久久久9999| 精品久久久久久久久久久久久久久| 久久综合国产乱子伦精品免费| 久久99国产精品久久99小说| 久久男人AV资源网站| 伊人色综合九久久天天蜜桃| 久久久久久久久久久精品尤物| 久久香综合精品久久伊人| 亚洲精品高清国产一线久久| 日韩久久久久中文字幕人妻| 中文精品久久久久国产网址| 99久久中文字幕| 97超级碰碰碰碰久久久久| 国产精品久久久久无码av| 狠狠色丁香婷综合久久| 国产高潮国产高潮久久久|