[MonoDevelop] [Patch] Mark T4-generated classes with 'partial'
Michael Hutchinson
m.j.hutchinson at gmail.com
Wed Dec 2 16:43:23 EST 2009
On Tue, Dec 1, 2009 at 8:42 PM, Olivier Dagenais
<olivier.dagenais at gmail.com> wrote:
>> Yup, I see no harm in it either. It should be especially useful when
>> we allow generating template classes from tt files within MD, like
>> VS2010 does (http://monodevelop.com/Developers/Tasks/Tools/T4#_task_a_T4.ClassGenerator).
>
> Cool, I already wrote code to make this happen for me with Visual
> Studio 2008. See
> <http://code.google.com/p/softwareninjas/source/detail?r=29> for the
> initial MSBuild task I wrote based on some of the code in
> GenerationTests. The T4 patches I have been submitting (a few more
> are on the way) are the changes I made to help make this happen.
>
> While I have your attention, I would like to discuss the next patch I
> was going to submit: fixing the multi-threading nightmare that is
> ToStringHelper. I realize it was Microsoft who introduced it, but I
> see no compelling reason to have the functionality it provides be
> implemented as a singleton. In my project, I incorporated its
> functionality as instance methods on TextTransformation so that
> parallel instances of TextTransformation (from the same or different
> template) could use their own IFormatProvider instances without
> risking a race condition in TemplatingEngine.Run().
>
> See <http://code.google.com/p/softwareninjas/source/detail?r=26> for
> my implementation, which suits my purposes. It has the side-effect
> that compiled templates would only need to reference
> TextTransformation and thus end-users could include Mono's
> implementation of TextTransformation.cs in their projects much the
> same way that end-users of Mono.Options can simply include
> Mono.Options.cs in their projects.
>
> In the general case, however, I think we would be better off adding a
> read-write property called FormatProvider to TextTransformation and
> thus avoid touching the TextTransformation constructor. As you can
> see in revision 26, I ended up painting myself into a corner with
> TemplatingEngine.cs with my first approach while the approach I'm
> proposing here (i.e. the property) would be simpler because it
> wouldn't have to deal with instantiation by reflection.
>
> What do you think?
I'd like to do it in a way that's compatible with VS2010, but I'm sure
we can make improvements.
This has a good explanation of how VS2010 handles preprocessed text templates:
http://www.olegsych.com/2009/09/t4-preprocessed-text-templates/
It looks like VS 2010 emits all the needed helpers into the generated
code if they're not present on the base class, so it may be that we
could indeed just place the ToStringHelper on the default base class
and remain compatible.
A quick hack for your use case would be to use [ThreadStatic] on the
ToStringHelper fields. It's slowish, but probably faster than locking.
--
Michael Hutchinson
http://mjhutchinson.com
More information about the Monodevelop-list
mailing list