0

Hi I'm building a small framework to help me build app quickly. I'm using Generics all sort of techniques that help me avoid to write boilerplate code repetitively.

I think it's a good idea, for my framework, to generate some code based on model objects, I know that JIT compilation is not available in MonoTouch but, I think it should be useful to generate code immediately before the compilation, using some templates.

Is there an utility that could help me to generate code before compilation in MonoTouch?

Anyone experimented this approach?

  • I'm looking at T4 Templates in MonoDevelop [link]http://mjhutchinson.com/journal/2010/05/03/t4_templates_monodevelop[/link] seems interesting... –  Oct 10 '12 at 12:12
  • To be more specific. I'm going to generate standard controllers for domain objects based on templates. –  Oct 10 '12 at 12:14

2 Answers2

0

I don't see why it would be useful to generate additional code, unless you have a very specific reason for doing so.

The AOT process in MonoTouch will automatically determine the generic types you're using and only generate native code for those.

The specific reason you might have is that there are certain cases where the AOT compiler can't determine which generic types you're using (but you shouldn't try to solve this problem before you actually run into it - generating code just in case will only make your compile times slower, your app bigger, the upload to device / install process will be slower... without any gain).

Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86
  • To be more specific. I'm going to generate standard controllers for domain objects based on templates and using code like: `List lst = new List();` –  Oct 10 '12 at 12:26
  • You seem to be a bit confused with AOT/JIT: if you want to generate code for your own purpose in your project, that's perfectly fine, just generate the files and add them to your project - whether you're using AOT or JIT during executing is irrelevant. – Rolf Bjarne Kvinge Oct 10 '12 at 12:54
  • Yes you are right, maybe the AOT is a misleading term. I used it to remark that I cannot JIT compile with MonoTouch. I have some code that I can run with JIT compiler but, since MonoTouch have no JIT I decided to change approach. Do you know any solution for code generation in MonoTouch anyway? –  Oct 10 '12 at 13:23
  • There is no need to change approach because MonoTouch has no JIT (unless you run into any AOT limitations). – Rolf Bjarne Kvinge Oct 10 '12 at 16:52
  • Don't consider AOT (the word was eliminated from title). I would like to implement some sort of scaffolding for my app. Is there a way to do it in MonoToch/MonoDevelop? –  Oct 10 '12 at 17:48
  • Unfortunately I don't know about anything in that area. – Rolf Bjarne Kvinge Oct 10 '12 at 20:50
0

Use T4 template on MonoDevelop like you use in VS.

Create a new file with .tt extension and content like this:

<#@ template language="C#v3.5" #>
<#@ assembly name="Path/To/your/assembly" #>

<#@ import namespace="Your.Namespace1" #>
<#@ import namespace="Your.Namespace1" #>

// Write your T4 template transformations. 

Every time you save the .tt file, a nested .cs file will be generated.

giacomelli
  • 7,287
  • 2
  • 27
  • 31