开发者

Generate .xaml and .xaml.cs with Template T4

I am new in T4 Template and i want to generate .xaml files from T4 and taking some information form .xml file. So my question is: is it possible to generate .xaml files and all the M开发者_Python百科VVM infrastructure from T4 and is it possible to call and generate different files from T4 Template file ? Is it the best way to choose T4 Template for generation of wpf screens ? If not, how can we do for generating generic screens quickly ?


I see 5 questions:

  1. Is it possible to generate .xaml files and all the MVVM infrastructure from T4?
  2. Is it possible to call different files from T4 Template file?
  3. Is it possible to generate different files from T4 Template file?
  4. Is it the best way to choose T4 Template for generation of wpf screens?
  5. If not, how can we do for generating generic screens quickly?

Here are my answers:

  1. Yes, actually I believe T4 is very well suited to generate the boiler plate code that is usually required for MVVM.
  2. Yes, if you by this question mean that you wish to have a library of templates that you can reuse. The mechanism you use to get code-reuse in T4 is either normal assemblies that you reference or the <#@ include #> directive (very much like includes in PHP or ASP)
  3. Yes, but I would recommend you not to do this. Attempting this complicates the templates significantly and you should ask yourself what is the benefit of having different files for different generated classes. In certain cases you might be required to have seperate files (ie C# and XAML have to live in different files) but I would then recommend having two template files with diffent <#@ output #> directives.
  4. I don't understand this question, perhaps you can elaborate?
  5. It sounds like LightSwitch could be of interest to you. You could still use T4 to generate the model fragments needed for the screens.

In conclusion if you are looking for good resources on how to use T4 visit Oleg Sych's blog on T4. It's excellent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜