diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..da556a028956745f8abedc8cc381d1bffc2014ea --- /dev/null +++ b/README.en.md @@ -0,0 +1,117 @@ +# GeoFive.Shared.CAD.Abstractions + +An abstraction layer for command menus in CAD applications, providing a unified mechanism for defining menu commands across CAD platforms such as AutoCAD. + +## Core Features + +- **MenuInfoAttribute**: A custom attribute used to mark CAD command methods. +- **Reflection-based Automatic Discovery**: Supports automatic discovery and registration of menu commands via reflection. +- **Cross-Version Compatibility**: Compatible with different versions of CAD platforms. + +## Installation Instructions + +### .NET CLI + +```bash +dotnet add package GeoFive.Shared.CAD.Abstractions +``` + +### Package Manager Console + +```powershell +Install-Package GeoFive.Shared.CAD.Abstractions +``` + +### csproj Reference + +```xml + +``` + +## Quick Start and Usage Guide + +### 1. Mark Command Methods with MenuInfoAttribute + +```csharp +using GeoFive.Shared.CAD.Abstractions; + +public class MyCommands +{ + [MenuInfoAttribute("Drawing", 1, "Draw Rectangle", 1)] + public void DrawRectangle() + { + // Implement logic to draw a rectangle + } + + [MenuInfoAttribute("Drawing", 1, "Draw Circle", 2)] + public void DrawCircle() + { + // Implement logic to draw a circle + } +} +``` + +### 2. Automatically Discover and Register Menus via Reflection + +```csharp +// Scan all command classes in the assembly and register menus +var commandTypes = Assembly.GetExecutingAssembly() + .GetTypes() + .Where(t => t.GetMethods() + .Any(m => m.IsDefined(typeof(MenuInfoAttribute), false))); + +foreach (var type in commandTypes) +{ + var methods = type.GetMethods() + .Where(m => m.IsDefined(typeof(MenuInfoAttribute), false)) + .Select(m => new + { + Method = m, + Attr = m.GetCustomAttribute() + }); + + foreach (var method in methods) + { + Console.WriteLine($"Menu Group: {method.Attr.GroupName}, " + + $"Command: {method.Attr.CommandName}, " + + $"Index: {method.Attr.CommandIndex}"); + } +} +``` + +## API Overview + +### MenuInfoAttribute + +Attribute class used to mark CAD command methods. + +```csharp +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public class MenuInfoAttribute : Attribute +``` + +#### Constructor + +```csharp +public MenuInfoAttribute(string groupName, int groupIndex, string commandName, double commandIndex) +``` + +#### Properties + +| Property | Type | Description | +|----------|------|-------------| +| GroupName | string | Name of the menu group | +| GroupIndex | int | Index of the menu group | +| CommandName | string | Name of the command | +| CommandIndex | double | Index of the command | + +## Supported Platforms and Ecosystem + +- AutoCAD +- Other .NET-based CAD platforms +- GIS applications +- Custom plugin development + +## License + +This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..71c638717e7b011458009b3e7e2ba12ca1cc96c9 --- /dev/null +++ b/README.md @@ -0,0 +1,117 @@ +# GeoFive.Shared.CAD.Abstractions + +CAD 应用程序的命令菜单抽象层,为 AutoCAD 等 CAD 平台提供统一的菜单命令定义机制。 + +## 核心特性 + +- **MenuInfoAttribute**:自定义特性,用于标记 CAD 命令方法 +- **反射自动发现**:支持通过反射自动发现和注册菜单命令 +- **跨版本兼容**:支持不同的 CAD 平台版本 + +## 安装说明 + +### .NET CLI + +```bash +dotnet add package GeoFive.Shared.CAD.Abstractions +``` + +### Package Manager Console + +```powershell +Install-Package GeoFive.Shared.CAD.Abstractions +``` + +### csproj 引用 + +```xml + +``` + +## 快速上手与使用指南 + +### 1. 使用 MenuInfoAttribute 标记命令方法 + +```csharp +using GeoFive.Shared.CAD.Abstractions; + +public class MyCommands +{ + [MenuInfoAttribute("绘图", 1, "绘制矩形", 1)] + public void DrawRectangle() + { + // 实现绘制矩形的逻辑 + } + + [MenuInfoAttribute("绘图", 1, "绘制圆形", 2)] + public void DrawCircle() + { + // 实现绘制圆形的逻辑 + } +} +``` + +### 2. 通过反射自动发现与注册菜单 + +```csharp +// 扫描程序集中的所有命令类并注册菜单 +var commandTypes = Assembly.GetExecutingAssembly() + .GetTypes() + .Where(t => t.GetMethods() + .Any(m => m.IsDefined(typeof(MenuInfoAttribute), false))); + +foreach (var type in commandTypes) +{ + var methods = type.GetMethods() + .Where(m => m.IsDefined(typeof(MenuInfoAttribute), false)) + .Select(m => new + { + Method = m, + Attr = m.GetCustomAttribute() + }); + + foreach (var method in methods) + { + Console.WriteLine($"菜单组: {method.Attr.GroupName}, " + + $"命令: {method.Attr.CommandName}, " + + $"索引: {method.Attr.CommandIndex}"); + } +} +``` + +## API 概览 + +### MenuInfoAttribute + +用于标记 CAD 命令方法的特性类。 + +```csharp +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public class MenuInfoAttribute : Attribute +``` + +#### 构造函数 + +```csharp +public MenuInfoAttribute(string groupName, int groupIndex, string commandName, double commandIndex) +``` + +#### 属性 + +| 属性 | 类型 | 描述 | +|------|------|------| +| GroupName | string | 菜单组名称 | +| GroupIndex | int | 菜单组索引 | +| CommandName | string | 命令名称 | +| CommandIndex | double | 命令索引 | + +## 适用平台与生态 + +- AutoCAD +- 其他基于 .NET 的 CAD 平台 +- GIS 应用程序 +- 二次开发插件 + +## 许可证 + +本项目采用 MIT 许可证。详情请参阅 [LICENSE](./LICENSE) 文件。 \ No newline at end of file