NavisworksTransport/.serena/memories/coding_standards.md

82 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 编码规范和约定
## 语言和注释
- **主要语言**: 中文用于所有交流和代码注释
- **注释风格**: 详细的中文注释解释功能和目的
- **文档**: 技术文档使用中文
## 命名约定
- **类名**: PascalCase (如PathPlanningManager)
- **方法名**: PascalCase (如UpdateAnimationUI)
- **私有字段**: _camelCase前缀下划线 (如_animationStatusLabel)
- **公共属性**: PascalCase (如IsAnimationRunning)
- **常量**: UPPER_CASE或PascalCase
## 线程安全模式(重要)
### 标准UI更新模式
```csharp
if (control.InvokeRequired)
{
control.BeginInvoke(new Action(() =>
{
try
{
// UI更新逻辑
control.Property = newValue;
}
catch (Exception ex)
{
LogManager.Error($"UI更新失败: {ex.Message}");
}
}));
}
else
{
// 直接执行UI更新逻辑
control.Property = newValue;
}
```
### 批量更新模式ListView等
```csharp
// 1. 后台准备数据
var items = new List<ListViewItem>();
// ... 准备数据 ...
// 2. 线程安全批量更新
if (listView.InvokeRequired)
{
listView.BeginInvoke(new Action(() =>
{
try
{
if (listView != null && !listView.IsDisposed)
{
listView.Items.Clear();
listView.Items.AddRange(items.ToArray());
}
}
catch (Exception ex)
{
LogManager.Error($"ListView更新失败: {ex.Message}");
}
}));
}
```
## 插件注册模式
```csharp
[Plugin("NavisworksTransport.MainPlugin", "YourDeveloperID")]
[AddInPlugin(AddInLocation.AddIn)]
public class MainPlugin : AddInPlugin { }
```
## 异常处理
- 使用GlobalExceptionHandler进行应用级异常处理
- 在UI更新中使用try-catch保护
- 详细的错误日志记录使用LogManager
## API使用原则
- **优先使用**: Navisworks Native API (Autodesk.Navisworks.Api)
- **辅助使用**: COM API (Autodesk.Navisworks.ComApi) 用于属性持久化
- **避免**: 直接使用未检查的API调用