如何在DSL T4模板中引用图表? [英] How do I reference a diagram in a DSL T4 template?
问题描述
在这里,Google并没有帮助我,我只是知道,这是一个完美的询问地点。
Google's not coming to my rescue, here, and I just know this is the perfect place to ask.
我在写DSL的自定义DirectiveProcessor,我希望能够从T4模板中访问图表。
I'm writing a custom DirectiveProcessor for a DSL and I want to be able to access a diagram from within my T4 template.
在DirectiveProcessor中,我已经加载了域模型和图(使用...等待)LoadModelAndDiagram(...)。
Within my DirectiveProcessor, I've loaded the domain model and my diagram using (wait for it...) LoadModelAndDiagram(...).
因此,现在该图已加载到商店的默认分区中,但是我可以在我的一生中,t找出以后如何解决对它的引用。
So, now the diagram's loaded into the default partition in the Store, but I can't for the life of me work out how to resolve a reference to it later.
任何人都可以提供指导吗?
Can anyone guide the way?
推荐答案
嗯,经过大量的后续工作,我决定不需要**从内部访问我的图**一个自定义DirectiveProcessor。
Well, after lots of further work, I decided I didn't need to access my diagram **from within** a custom DirectiveProcessor.
我仍然有一个自定义DirectiveProcessor,因为生成的标准在加载域模型时不会加载现有图。
I've still got a custom DirectiveProcessor because the standard generated one doesn't load the existing diagram when it loads the domain model.
获取自定义DirectiveProcessor来同时加载图和模型非常容易。您可以将生成的标准DirectiveProcessor基类子类化并覆盖:
Getting a custom DirectiveProcessor to load the diagram and model at the same time is trivially easy. You subclass the standard generated DirectiveProcessor base class and override:
protected override bool LoadDiagramData
{
get
{
return true;
}
}
现在,我们已经加载了图表,因此回到最初的问题,我们如何访问它?像这样:
Now, we have the diagram loaded, so to get back to the original question, how do we access it? Like this:
using (Transaction t = partition.Store.TransactionManager
.BeginTransaction("MyTxn", true))
{
MyDslDiagram diagram = partition.ElementDirectory
.FindElements<MyDslDiagram>(true).SingleOrDefault();
/*
* Now, do stuff with your diagram.
*
*/
}
现在,此代码有效如果您已加载图表,那很好。否则,图将返回为 null ,在这种情况下,我们要么必须显式加载该图,要么动态创建该图。
Now, this code works just fine if you have a diagram loaded. If you don't, diagram will come back as null, in which case, we either have to load the diagram explicitly or create one dynamically.
在这里,我不讨论它。睡觉后,也许在我的博客上!
I won't go into that, here. Maybe on my blog when I've had some sleep!
这篇关于如何在DSL T4模板中引用图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!