GeoFive.Shared.CAD.Abstractions
1.0.0
dotnet add package GeoFive.Shared.CAD.Abstractions --version 1.0.0
NuGet\Install-Package GeoFive.Shared.CAD.Abstractions -Version 1.0.0
<PackageReference Include="GeoFive.Shared.CAD.Abstractions" Version="1.0.0" />
<PackageVersion Include="GeoFive.Shared.CAD.Abstractions" Version="1.0.0" />
<PackageReference Include="GeoFive.Shared.CAD.Abstractions" />
paket add GeoFive.Shared.CAD.Abstractions --version 1.0.0
#r "nuget: GeoFive.Shared.CAD.Abstractions, 1.0.0"
#:package GeoFive.Shared.CAD.Abstractions@1.0.0
#addin nuget:?package=GeoFive.Shared.CAD.Abstractions&version=1.0.0
#tool nuget:?package=GeoFive.Shared.CAD.Abstractions&version=1.0.0
GeoFive.Shared.CAD.Abstractions
GeoFive 生态系统的企业级通用基础设施。
本包为 CAD(如 AutoCAD、中望 CAD、浩辰 CAD 等)二次开发提供零依赖、跨平台的通用契约、菜单路由特性与底层基础抽象。
🌟 核心特性
- 零外部依赖
基于netstandard2.0构建,轻量纯净,既可兼容以.NET Framework运行的传统 CAD 平台,也适用于支持.NET Core / .NET 5+的现代跨平台 CAD 环境。 - 声明式菜单与命令元数据 (
[MenuInfo])
通过简单直观的MenuInfoAttribute特性,为方法提供菜单分组、组内排序及命令项排序信息,助力实现自动化扫描构建功能面板和功能菜单树。 - 高拓展性架构
解耦业务层逻辑与底层 CAD 主机 API,为 CAD 插件工程化的模块发现、依赖注入及统一排版路由提供抽象层支撑。
📦 安装说明
通过 NuGet 包管理器或 .NET CLI 安装核心包:
.NET CLI
dotnet add package GeoFive.Shared.CAD.Abstractions
Package Manager Console
Install-Package GeoFive.Shared.CAD.Abstractions
csproj 引用
<PackageReference Include="GeoFive.Shared.CAD.Abstractions" Version="1.0.0" />
🚀 快速上手与使用指南
1. 使用 MenuInfoAttribute 标记命令方法
在您的 CAD 功能命令模块或控制器方法上,通过标记 [MenuInfo] 声明当前功能的分组名称、分组排序、命令名称以及命令内排布顺序。
using GeoFive.Shared.CAD.Abstractions;
public class ProfileDrawCommands
{
/// <summary>
/// 绘制地层剖面图
/// </summary>
[MenuInfo(groupName: "剖面建模", groupIndex: 1, commandName: "绘制剖面", commandIndex: 1.0)]
[CommandMethod(nameof(DrawGeologicalProfile))]
public void DrawGeologicalProfile()
{
// CAD 绘图执行逻辑
}
/// <summary>
/// 标注剖面高程
/// </summary>
[MenuInfo(groupName: "剖面建模", groupIndex: 1, commandName: "标定高程", commandIndex: 2.0)]
[CommandMethod(nameof(AnnotateElevation))]
public void AnnotateElevation()
{
// 高程标注逻辑
}
/// <summary>
/// 导出计算报表
/// </summary>
[MenuInfo(groupName: "结果导出", groupIndex: 2, commandName: "导出报表", commandIndex: 1.0)]
[CommandMethod(nameof(ExportReport))]
public void ExportReport()
{
// 报表导出逻辑
}
}
2. 通过反射自动发现与注册菜单
在框架加载或插件初始化的阶段,通过反射扫描程序集中公共类(Public Class)下标注了 MenuInfoAttribute 的所有公共方法(无论是静态方法还是实例方法),自动生成分层次的菜单与工具栏项:
using System;
using System.Linq;
using System.Reflection;
using GeoFive.Shared.CAD.Abstractions;
public static class MenuDiscovery
{
public static void DiscoverAndRegisterMenus(Assembly assembly)
{
// 1. 获取程序集中所有公共类 (Public Class)
// 2. 获取公共类下所有公共方法 (支持静态方法或实例方法,不限定必须单例或静态)
var methods = assembly.GetExportedTypes()
.Where(t => t.IsClass)
.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
.Select(m => new { Method = m, Attribute = m.GetCustomAttribute<MenuInfoAttribute>() })
.Where(x => x.Attribute != null)
.OrderBy(x => x.Attribute.GroupIndex)
.ThenBy(x => x.Attribute.CommandIndex);
foreach (var item in methods)
{
var info = item.Attribute;
Console.WriteLine($"[分组 {info.GroupIndex}: {info.GroupName}] -> 命令 {info.CommandIndex}: {info.CommandName}");
// 在此将其注册为 CAD 平台的 Ribbon 按钮、右键菜单或下拉命令
// 提示:若是实例方法(Instance Method),可在命令触发时结合 DI 容器或构造反射实例化对应类并调用
}
}
}
📖 API 概览
MenuInfoAttribute
用于方法注解([AttributeUsage(AttributeTargets.Method)]),声明菜单与命令调度的基础描述。
| 属性 / 构造参数 | 类型 | 说明 |
|---|---|---|
| GroupName | string |
菜单分组/功能模块的显示名称(如:剖面建模) |
| GroupIndex | int |
分组在界面或主菜单上的排布顺序(数值越小越靠前) |
| CommandName | string |
功能按钮或具体命令名称(如:绘制剖面) |
| CommandIndex | double |
命令在当前分组内的相对排布顺序,采用浮点数以便于后续灵活插入调整 |
📁 适用平台与生态
本抽象层保持环境解耦,可在以下常见 CAD 平台上开发兼容层:
- AutoCAD (.NET API)
- 中望 CAD (ZWCAD .NET)
- 浩辰 CAD (GstarCAD .NET)
- AnyCAD 及其他图形及设计系统
📄 许可证 (License)
Copyright © GeoFive Team. All rights reserved.
本项目采用 LICENSE 声明的授权许可。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 117 | 7/14/2026 |
初始化发布 GeoFive.Shared.CAD 核心抽象与菜单特性定义。