cad c# 二次开发 ——动态加载dll 文件制作(loada netloadx)

原理:制作一个dll工具,此dll工具可动态加载调试代码所生成的dll。

using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using LoadaDotNet;
namespace load
{
  public class Class1
  {
    private bool ev = false;
    [CommandMethod("netloadx")]
        public void Netloadx()//输入netloadx可动态加载程序的二进制文件
        {
            //IL_0017: Unknown result type (might be due to invalid IL or missing references)
            //IL_001d: Expected O, but got Unknown
            //IL_0036: Unknown result type (might be due to invalid IL or missing references)
            //IL_003c: Invalid comparison between Unknown and I4
            Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            string text = "山水qq443440204";
            OpenFileDialog val = new OpenFileDialog();
            ((FileDialog)val).Filter = "dll文件(*.dll)|*.dll";
            ((FileDialog)val).Title = "打开dll文件";
            if ((int)((CommonDialog)val).ShowDialog() != 1)
            {
                return;
            }

            text = ((FileDialog)val).FileName;
            AssemblyDependent assemblyDependent = new AssemblyDependent(text);
            bool flag = true;
            AssemblyDependent.LoadDllMessage[] array = assemblyDependent.Load().ToArray();
            foreach (AssemblyDependent.LoadDllMessage loadDllMessage in array)
            {
                if (!loadDllMessage.LoadYes)
                {
                    editor.WriteMessage("\n" + loadDllMessage.Path + "失败!");
                    flag = false;
                }
            }

            if (flag)
            {
                editor.WriteMessage("\n加载成功!\n");
            }
        }
        [CommandMethod("ww")]
        public void ww()//输入ww可自动加载目录下的ifoxdemo
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var ad = new AssemblyDependent(@"G:\Csharp\Ifox\IfoxDemo\IfoxDemo\bin\Debug\net48\IfoxDemo.dll");  //写上你dll的路径
            var msg = ad.Load();

            bool allyes = true;
            foreach (var item in msg)
            {
                if (!item.LoadYes)
                {
                    ed.WriteMessage("\n**" + item.Path + "**重复版本号,无需再次加载!" + System.Environment.NewLine);
                    allyes = false;
                }
            }
            if (allyes)
            {
                ed.WriteMessage("\n加载成功!\n");
            }
            if (!ev) { System.AppDomain.CurrentDomain.AssemblyResolve += RunTimeCurrentDomain.DefaultAssemblyResolve; ev = true; }

        }
        [CommandMethod("www")]
        public void www()//输入www自动加载路径下的demo.dll
        {
          var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
          var db = doc.Database;
          var ed = doc.Editor;
          var ad = new AssemblyDependent(@"G:\Csharp\Demo\Demo\bin\Debug\Demo.dll");  //写上你dll的路径
          var msg= ad.Load();

          bool allyes = true;
          foreach (var item in msg)
          {
            if (!item.LoadYes)
            {
              ed.WriteMessage("\n**" + item.Path +"**重复版本号,无需再次加载!" + System.Environment.NewLine);
              allyes = false;
            }
          }
          if (allyes)
          {
            ed.WriteMessage( "\n加载成功!\n");
          }
          if (!ev) { System.AppDomain.CurrentDomain.AssemblyResolve += RunTimeCurrentDomain.DefaultAssemb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山水CAD插件定制

你的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值