26

TSL初体验:构建一个简单的Cell

 4 years ago
source link: https://blog.csdn.net/shyleoking/article/details/105219780
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

一切从控制台应用开始。

建立控制台应用

确保安装了GraphEngineVSExtension.vsix插件

管理你的NuGet程序包,从GraphEngine OSS Location安装GraphEngine.Core

然后添加新项

qANZfim.png!web

其实这两没有啥区别,都是TSL文件。不过模板给我们做了一些样例代码,那我们就选择DataModel(第二个),我们会看到TSL已经给了一个样例代码

cell MyCell
{
	int A;
}

如我们之前说的,TSL可以帮助我们定义数据模型,并且通过IDL进行数据消息的通知和解析。所以有两件事情要记得

  • TSL中的代码格式虽然和C#很像,但不是C#的代码,也不是你的C#代码可以直接访问的
  • TSL定义的是数据模型,所以cell中不能定义方法,也不能定义属性。简单的说,除了字段,cell中啥都不能定义

那我们的cell怎么使用呢?GraphEngine会把cell的结构编译为一组对象,帮助我们进行单元的访问,存储和使用。

现在到你的Program你会看到

MZz2Y3n.png!web

GraphEngine生成了

  • 一个MyCell对象
  • 一组MyCell_Accessor访问器
  • MyCell_Enumerable
  • 一组选择器MyCell_local_selector
  • 在Global.LocalStorage加入了一组MyCell的访问成员
    • Is
    • Load
    • Save
    • Use

这些成员可以帮助我们进行对MyCell的各种数据处理。

官方的样例代码中有这些的写法

cell struct SimpleGraphNode
{
    List<CellId> Inlinks;
    List<CellId> Outlinks;
    string Name;
}

但目前看来,不建议大家用struct 关键字。我们要构建单元,直接用cell就可以了。

cell可以用Attributes修饰,和C#不同,我们不需要预先定义Attributes,直接声明就可以了

[GraphNode, BaseType : Person]
cell Student
{
    [GraphEdge : Outlinks]
    List<CellId> friends;
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK