标签:clsName AutoCAD string C# List 导出 item dllName public
主函数导出某一程序集AutoCAD 注册命令
/// <summary> ///提取所有的命令 /// </summary> /// <param name="dllFiles">dll的路径</param> /// <returns></returns> public static List<gcadDllcmd> GetDllCmds(params string[] dllFiles) { List<gcadDllcmd> res = new List<gcadDllcmd>(); List<gcadCmds> cmds = new List<gcadCmds>(); #region 提取所以的命令 for (int i = 0; i < dllFiles.Length; i++) { Assembly ass = Assembly.LoadFile(dllFiles[i]);//反射加载dll程序集 var clsCollection = ass.GetTypes().Where(t => t.IsClass && t.IsPublic).ToList(); if (clsCollection.Count > 0) { foreach (var cls in clsCollection) { var methods = cls.GetMethods().Where(m => m.IsPublic && m.GetCustomAttributes(true).Length > 0).ToList(); if (methods.Count > 0) { foreach (MethodInfo mi in methods) { var atts = mi.GetCustomAttributes(true).Where(c => c is CommandMethodAttribute).ToList(); if (atts.Count == 1) { gcadCmds cmd = new gcadCmds(cls.Name, mi.Name, (atts[0] as CommandMethodAttribute).GlobalName, ass.ManifestModule.Name.Substring(0, ass.ManifestModule.Name.Length - 4)); cmds.Add(cmd); } } } } } } #endregion if (cmds.Count > 0) { List<string> dllName = new List<string>(); foreach (var item in cmds) { if (!dllName.Contains(item.dllName)) dllName.Add(item.dllName); } foreach (var item in dllName) res.Add(new gcadDllcmd(item, cmds)); } return res; // }
1# 定义自定义的class,
/// <summary> /// 储存自定义的cad命令的信息的类 /// </summary> public class gcadCmds { public string clsName { get; set; } public string cmdName { get; set; } public string cmdMacro { get; set; } public string dllName { get; set; } public gcadCmds(string _clsName, string _cmdName, string _macro, string _dllName) { this.dllName = _dllName; this.clsName = _clsName; this.cmdMacro = _macro; this.cmdName = _cmdName; } }
2# 定义类
/// <summary> /// 储存包含自定命令的类 /// </summary> public class gcadClscmd { public string clsName { get; set; } public string dllName { get; set; } public bool HasGcadcmds { get; set; } public List<gcadCmds> curClscmds { get; set; } public gcadClscmd(string _clsName, List<gcadCmds> cmds) { this.clsName = _clsName; this.dllName = cmds.First().dllName; var clsCmds = cmds.Where(c => c.clsName == this.clsName).ToList(); if (clsCmds.Count > 0) { this.HasGcadcmds = true; this.curClscmds = new List<gcadCmds>(); foreach (var item in clsCmds) { if (item.clsName == this.clsName) this.curClscmds.Add(item); } } else this.HasGcadcmds = false; } }
3# 存储每个dll的
/// <summary> /// 储存每个dll类的 /// </summary> public class gcadDllcmd { public string DllName { get; set; } public bool HasGcadcls { get; set; } public List<gcadClscmd> clsCmds { get; set; } public List<gcadCmds> curDllcmds { get; set; } public gcadDllcmd(string _dllname, List<gcadCmds> cmds) { this.DllName = _dllname; var curDllcmds = cmds.Where(c => c.dllName == this.DllName).ToList(); if (curDllcmds.Count > 0) { this.HasGcadcls = true; this.curDllcmds = curDllcmds; List<string> listClsName = new List<string>(); foreach (gcadCmds item in this.curDllcmds) { if (!listClsName.Contains(item.clsName)) listClsName.Add(item.clsName); } this.clsCmds = new List<gcadClscmd>(); foreach (var item in listClsName) { gcadClscmd clsCmds = new gcadClscmd(item, this.curDllcmds.Where(c => c.clsName == item).ToList()); this.clsCmds.Add(clsCmds); } } else this.HasGcadcls = false; } }
标签:clsName,AutoCAD,string,C#,List,导出,item,dllName,public 来源: https://www.cnblogs.com/NanShengBlogs/p/10957636.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。