c# - 一个类方法之间类库中的数据持久化

标签 c# .net autocad

我正在使用 .NET 为 AutoCAD 创建类库。

问题是这些方法从 AutoCAD 中一个接一个地被调用,第一个方法读取输入文件并在内存中创建数据列表。但是,当调用新列表时,列表是空的。

我需要找到一个解决方案来保存这些数据。 该列表包含我创建的结构中的数据。方法独立调用,但按顺序调用。

短代码示例:

namespace GeoPjuvis
{
   ...

public class Program
{
    ...

//program variables 
private List<GeoData> dataList;
private List<DataPoint> points;
private int mapScale;

public Program()
{
    dataList = new List<GeoData>();
    points = new List<DataPoint>();
}

//Initialization method of the program. Makes praperations. Reads files. Add points to map.
[CommandMethod("geoinit", CommandFlags.Session)]
public void Init()
{
    ...
}

//method uses data gathered before and selects points  
[CommandMethod("selectPoints", CommandFlags.Session)]
public void SelectPoints()
{

    ...

}...

那么为什么当我调用 SelectPoints() 方法时这些数据列表和点列表是空的。以及如何避免这种情况?

最佳答案

我不知道 AutoCAD 的编程,但我怀疑它每次都在创建一个新实例。您可以尝试将变量设为静态(例如类级别):

private static List<GeoData> dataList = new List<GeoData>();

关于c# - 一个类方法之间类库中的数据持久化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3281106/

相关文章:

c# - 从 C# 在 powershell 中运行 AD 命令行开关时出错

c# - View 在屏幕上时如何修改 XAML 元素的颜色?

c# - UriBuilder 没有正确组合两个 URI

.net - GetVstoObject 失败并出现 AccessViolationException

c# - 如何在运行时动态创建 Action<T>?

c# - 监视特定文件关闭 c#

C# Expression Tree调用基类属性get方法

c# - FileSystemWatcher 无法正常工作

c# - 读取 .DXF 文件

api - 我可以使用 Autodesk 查看 API 将本地 DWG (2D) 文件渲染到我的浏览器吗?