t4

T4 FieldName in camelCase without Underscore?

I'm using T4 to generate some class definitions and find that I'm getting an underscore in front of my field names. I have set code.CamelCaseFields = true; just to be safe (even though I understand that's the default) but still end up with _myField rather than myField. How can I generate a field name without the '_'? Also, where is...

Debugging T4 Template in VS 2010 Crashes IDE

I'm trying to debug a slightly-modified version of the ADO.NET POCO Entity Generator template using the directions Oleg Sych published a few years back. I modified the DbgJITDebugLaunchSetting key as recommended. I get a dialog indicating that a user-defined breakpoint has been hit. However, rather than being presented with the option...

One Model to Rule Them All - VS2010 UML, ADO.NET Entity Data Model, and T4

I worked on a fairly large project a while back where we modeled the classes in Enterprise Architect and generated the (partial) POCO classes (complete with model-driven business rule validations), persistence (NHibernate mapping file) and DDL. Based on certain model attributes we could flag alternate generation strategies or indicate t...

Automatic INotifyPropertyChanged Implementation through T4 code generation?

I'm currently working on setting up a new project of mine and was wondering how I could achieve that my ViewModel classes do have INotifyPropertyChanged support while not having to handcode all the properties myself. I looked into AOP frameworks but I think they would just blow up my project with another dependency. So I thought about ...

How do I run a .NET Unit Test repeatedly with a set of parameters cartesianed

I have 1 unit test method that needs several parameters. I would like to run this test once for every possible value of a cartesian with a predefined list for each parameter. I imagine that parameters could be passes in via the test context, but I do not want to connect to an external database. For example: If I had 2 parameters with...

Assembly with T4 templates for use in other Solutions?

I just finished creating T4 templates to auto-generate property implementations for my ViewModel classes (see here: http://stackoverflow.com/questions/2968406/automatic-inotifypropertychanged-implementation-through-t4-code-generation). Currently I need to have the project holding the ".tt"-files in the solution where I want to generate ...

Entity Framework 4, Self Tracking Entities T4 Template, ApplyChanges() extension method

I am using EF4 and the built in self-tracking entities template to generate my entites from my model. I also modifeid the T4 template so that all of the references to "ObjectContext" were changed to "IObjectContext", and I applied an interface to the auto generated context (all this was for testing and mocking purposes). //my interfa...

Determining whether a class implements a generic list in a T4 template

I'm writing a T4 template which loads some classes from an assembly, does some analysis of the classes and then generates some code. One particular bit of analysis I need to do is to determine whether the class implements a generic list. I can do this pretty simply in C#, e.g. public class Foo : List<string> { } var t = typeof(Foo); ...

Lambda Expressions in T4 Templates

Whilst putting together a T4 template I threw in a simple lambda expression: <#=string.Join(",", updateFields.ConvertAll(field => field.Name).ToArray())#> This causes the template to fail to generate with the error: Compiling transformation: Invalid expression term '>' On the line with the lambda expression. This has been check...

Linq-To-SQL Vs T4 Template.

I am using Linq-to-SQL for my projects but i heard about the T4 Template Code generator? Whether T4 Template is better then Linq-To-SQL Data Context? ...

Integrating DSLs with T4, and indicating script errors

Hi, everyone. I have an advanced T4 question and I'm hoping someone can help. I've created a SQL-like DSL, and the scripts are saved in '.satsql' files in my C# projects, like so; // contents of myqueries.satsql SELECT <column t1.Id> FROM <table mytable t1> I have a .tt file which loads the file and attempts to parse it. If it fails,...

Get controller name in View T4 template

I have a problem similar to the one described here: http://stackoverflow.com/questions/1128003/mvc-t4-mvctexttemplatehost-and-customized-controller-t4-template but hopefully, simpler. I have a custom View templates (View.tt, Create.tt) for ASP.NET MVC project. I can't figure out how to get the controller name in these view templates. mv...

T4 Template relative path

I have a T4Template: <#@ template language="C#" debug="True" hostspecific="True" #> <#@ output extension=".cs" #> <#@ assembly name="System.Web" #> <#@ assembly name="System.Web.Mvc" #> <#@ import namespace="System.Web.Mvc" #> <#@ import namespace="System.IO" #> <#@ import namespace="System.Web" #> using System; namespace MyNamespace...

Is there T4 templates available for generating c# classes from xsd?

Is there T4 templates available for generating c# classes from xsd? ...

T4 generating garbage ouput, tt file error free.

Hi, I'm trying to create a T4 template to generate a class for a specific task I need. However, something is broken with its output. The output file contains random garbage characters even when the .tt file is blank. I'm thinking it's something to do with the character encoding on the .tt file, maybe. I can successfully add a code g...

Excluding Nested Items from Source Control

I'm using T4 templating to generate some .config files in a project I'm working on. I've set up a pre-build task to look for all .tt files in the solution directory, and then execute the TextTransform command-line tool, so that the code is freshly generated on each build. However, I'm now having "Access Denied" errors because (for exam...

Referencing an assembly in a T4 template

It's been a while since I last used T4 and this is probably a silly question... Is it possible to reference an arbitrary assembly from a template? Example: I have a class that I'd like to use in Project X Project X.Test references X and contains the .tt file I assume the following should work <#@ assembly name="X" #> But I get t...

LINQ Query leaves all items with _IsTrue = true

Hi All, I have the following simple LINQ query (SubSonic 3.0.0.4 and ActiveRecord T4 templates). from item in PermissionsInRole.All() where item.RoleID == roleID select item When I iterate through the elements in the list after executing the query, IsNew = true for all of them, so if I make a change to an item and call.Save() it tri...

How to get T4 in VS2010 to iterate over class' properties

Hi, I'm using Visual Studio 2010, and have the tangibleT4EditorPlusModellingTools installed. I'm just playing around with T4, having never touched it previously. What I'd like to do is look at one of my classes in the project, and write out each of the properties. Could anyone give me absolute beginner tips to how the .tt file should...

How to get only user created properties using microsoft.cci Members?

I'm learning T4, and am successfully interrogating my custom class for its member. What I need however, is to bring out only the properties that I created, like FirstName, Surname, and Postcode. Here's an example of what I'm actually getting when I use : foreach(Microsoft.Cci.Member member in class.Members) { if( member.IsPublic ...