我想看一级黄色大片_久久亚洲国产精品一区二区_久久精品免视看国产明星_91久久青青青国产免费

您的位置:網(wǎng)站首頁 > CAD2008

在AutoCAD中程序化加載.NET程序集的方法(1)

時(shí)間:2010-01-23 23:45:32 來源:
前面的文章已經(jīng)介紹過,通過修改注冊表可以實(shí)現(xiàn).NET程序集隨AutoCAD的啟動自動加載,這兩天Kean又介紹了一種程序化的加載方法:用.NET程序加載.NET程序集,用到了微軟的核心類庫mscorlib中的System.Reflection命令空間。加載時(shí)只要一個(gè)函數(shù)Assembly.LoadFrom()可以了,試了下速度還是很快地。下面轉(zhuǎn)一下Kean的測試代碼(C#):

    1 using Autodesk.AutoCAD.ApplicationServices;

    2 using Autodesk.AutoCAD.EditorInput;

    3 using Autodesk.AutoCAD.Runtime;

    4 using System.Reflection;

    5 namespace LoadModule

    6 {

    7     public class Commands

    8     {

    9         [CommandMethod("MNL")]

   10         static public void MyNetLoad()

   11         {

   12             Document doc =

   13               Application.DocumentManager.MdiActiveDocument;

   14             Editor ed = doc.Editor;

   15             PromptStringOptions pso =

   16               new PromptStringOptions(

   17                 "n輸入要加載的程序集全路徑: "

#p#分頁標(biāo)題#e#

   18               );

   19             pso.AllowSpaces = true;

   20             PromptResult pr = ed.GetString(pso);

   21             if (pr.Status != PromptStatus.OK)

   22                 return;

   23             try

   24             {

   25                 Assembly.LoadFrom(pr.StringResult);

   26             }

   27             catch (System.Exception ex)

   28             {

   29                 ed.WriteMessage(

   30                   "n無法加載程序集{0}: {1}",

   31                   pr.StringResult,

   32                   ex.Message

   33                 );

   34             }

   35         }

   36#p#分頁標(biāo)題#e#     }

   37 }

  此方法給用戶隨時(shí)后臺(不知不覺地)加載.NET程序集提供了一種可能,美中不足的是托管的程序集目前只能加載無法卸載,一次加載終身受用,直到你關(guān)閉AutoCAD為至,呵呵。