• <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 悟山 閱讀(897) 評論(1)  編輯 收藏 引用

            Feedback

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

            偶遇留言  回復  更多評論   


            久久九九青青国产精品| 中文成人久久久久影院免费观看| 久久电影网| 一本一本久久a久久综合精品蜜桃| 久久精品国产亚洲av麻豆蜜芽| 亚洲成色www久久网站夜月| 久久精品国产亚洲精品| 无码精品久久久天天影视| 久久精品国产亚洲av影院| 一本大道久久东京热无码AV| 亚洲av伊人久久综合密臀性色 | 97精品伊人久久大香线蕉app| 久久精品这里只有精99品| 国产69精品久久久久9999APGF| AAA级久久久精品无码区| 久久99精品综合国产首页| 国产精品久久久久国产A级| 久久人人爽人人爽人人AV东京热| 久久精品卫校国产小美女| 国产综合成人久久大片91| 国产高潮国产高潮久久久| 亚洲天堂久久久| 久久亚洲精品成人无码网站 | 国产69精品久久久久9999| 久久亚洲精品人成综合网| 囯产极品美女高潮无套久久久| 日韩AV毛片精品久久久| 久久毛片一区二区| 久久综合久久鬼色| 国产欧美久久久精品影院| 久久久久国色AV免费看图片 | 久久精品国产亚洲av麻豆图片| 久久国产影院| 久久精品无码免费不卡| 人妻丰满?V无码久久不卡| 久久综合亚洲色HEZYO国产| 久久精品亚洲乱码伦伦中文| 国产精品内射久久久久欢欢| 久久99热这里只有精品国产| 精品久久久久中文字幕一区| 九九久久精品国产|