简体   繁体   English

如何在 DSL T4 模板中引用图表?

[英]How do I reference a diagram in a DSL T4 template?

Google's not coming to my rescue, here, and I just know this is the perfect place to ask.谷歌没有来救我,在这里,我只知道这是一个完美的提问地点。

I'm writing a custom DirectiveProcessor for a DSL and I want to be able to access a diagram from within my T4 template.我正在为 DSL 编写自定义 DirectiveProcessor,我希望能够从我的 T4 模板中访问图表。

Within my DirectiveProcessor, I've loaded the domain model and my diagram using (wait for it...) LoadModelAndDiagram(...).在我的 DirectiveProcessor 中,我已经使用(等待它...)LoadModelAndDiagram(...) 加载了域模型和我的图表。

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.所以,现在图表已加载到 Store 的默认分区中,但我终生无法解决以后如何解析对它的引用。

Can anyone guide the way?谁能指路?

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.让自定义 DirectiveProcessor 同时加载图表和模型非常容易。 You subclass the standard generated DirectiveProcessor base class and override:您子类化标准生成的 DirectiveProcessor 基类并覆盖:

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.
     *
     */
}

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.如果不这样做,图表将返回null ,在这种情况下,我们必须显式加载图表或动态创建图表。

I won't go into that, here.在这里,我不会深入讨论。 Maybe on my blog when I've had some sleep!也许在睡了一觉的时候在我的博客上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM