DSL 自定义构造函数 - 仅在创建时调用而不加载
信息:VS2010、DSL Toolkit、C#
我的域类之一有一个自定义构造函数,它添加了一些子元素。我有一个问题,因为我只希望在创建域类元素时运行它,而不是每次打开图(调用构造函数)时运行
public Entity(Partition partition, params PropertyAssignment[] propertyAssignments)
: base(partition, propertyAssignments)
{
if (SOMETHING_TO_STOP_IT_RUNNING_EACH_TIME)
{
using (Transaction tx = Store.TransactionManager.BeginTransaction("Add Property"))
{
Property property = new Property(partition);
property.Name = "Class";
property.Type = "System.String";
this.Properties.Add(property);
this.Version = "1.0.0.0"; // TODO: Implement Correctly
tx.Commit();
}
}
}
Info: VS2010, DSL Toolkit, C#
I have a custom constructor on one of my domain classes which adds some child elements. I have an issue as I only want this to run when the domain class element is created , not every time the diagram is opened (which calls the construtors)
public Entity(Partition partition, params PropertyAssignment[] propertyAssignments)
: base(partition, propertyAssignments)
{
if (SOMETHING_TO_STOP_IT_RUNNING_EACH_TIME)
{
using (Transaction tx = Store.TransactionManager.BeginTransaction("Add Property"))
{
Property property = new Property(partition);
property.Name = "Class";
property.Type = "System.String";
this.Properties.Add(property);
this.Version = "1.0.0.0"; // TODO: Implement Correctly
tx.Commit();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在从构造函数中初始化一些域类属性。最好通过创建 AddRule 来完成此操作。当 AddRules 所附加的域类的实例添加到模型中时,将调用 AddRules。例如:
然后需要通过覆盖域模型类中的函数来注册 AddRule:
有关规则的更多信息,请查看 VS SDK 文档中的“如何:创建自定义规则”主题。
注意:该解决方案基于 VS 2008 DSL Tools。 YMMV。
It looks like you are initializing some domain class properties from within the constructor. This is best done by creating an AddRule. AddRules are invoked when an instance of the domain class to which they are attached is added to the model. For example :
The AddRule then needs to be registered by overriding a function in your domain model class:
For more information about rules, have a look at the "How to: Create Custom Rules" topic in the VS SDK documentation.
Note: the solution is based on the VS 2008 DSL Tools. YMMV.
虽然不是正确的方法(Paul Lalonde 的答案是最好的),
您可以通过以下方式知道在任何给定时间模型是否正在序列化(= 加载):
Although not the correct approach (Paul Lalonde answer is the best),
here's how you may know, at any given time, if the model is being serialized (= loading):