How to specify template class visibility for a T4 preprocessed template? - c#

I have started adding some preprocessed T4 templates to a VS2010 C# library project. They are implementation details only, and I would prefer to not have them exposed on the library's API. I have not found a way to set the template's generated class visibility to 'internal'.
Is there a way? (If there is, I assume it will be something obvious that I have missed)
Thanks in advance,
/AI/

VS2012 has visibility="internal" on template.

Aethon,
Unfortunately there is no way to do this today short of post-processing the generated code in some fashion.
I'm looking at adding this for a future release of Visual Studio. If you wanted to log a Connect issue for this, that would be helpful.

Related

Wondering if we could generate code with T4 Template on a builded solution

I'm trying to figure out if we could generate code with a T4 Template file post-build.
In fact, I'm kinda new to c# and I needed to find a solution where I generate class from Xml file that could be edited by the user at anytime and the first solution that come to me is T4 Template.
Then I render those generated classes on a treeView and the according properties on a property grid.
Now, I think that it is only generate code at pre-build time, but I'm not sure about that since I don't really see a lot of stuff about that on the internet. I'm still pretty sure now that it's not possible.
So, a second problem comes to me : I finished my entire project like that, so if you all have an idea or another solution that could be nice, i'll really appreciate that.
The 'T4Executer' extension has an option to attach the execution of each T4 template to build events. Before, during and after build, or not run them at all.
Doesn't work for Visual Studio 2022 yet though.

Why use Xaml markup in Xamarin.Forms projects if i can do all job in C# file?

Why I should use Xaml markup in Xamarin.Forms projects if I can do all job in C# file? I think about this a lot time. I did not find answer about that in Google search. I think with C# I can do my apps faster than with using Xaml. Maybe someone know something fundamental about that? I'm new in Xamarin.Forms.
Why i should use Xaml markup in
It is easier to express visual coding patterns in Xaml as templates than to attempt it in code. Once a template is defined, say within a list, the data it represents will be repeated for each data item based on that one template.
It appears easier for you to code it, because I surmise you are now learning about Xaml and getting it working is the more important.
The rule of thumb is that Xaml specified should define a bare framework and the data will fill in that framework. By doing it in Xaml it can be created and more importantly updated using the Xaml design view (editor) to achieve the end goal.

Generate control C# code from NIB's and insert into MonoTouch's designer.cs files - Visual Studio style

I've begun using MonoTouch 5.x. I feel like I'm fighting NIB's to use inheritance.
I want to use inheritance. I want to use a designer to make my views. I want it all.
So I've been searching for a tool that generates xxx.designer.cs files like VS does it: inserting the controls in code on the fly when designing using IB. Reducing NIB's to a design-time feature.
As far as I can tell, this is the cleanest approach with the best performance that allows me to go full C#, "visual inheritance", etc.
Does anyone know of such an initiative? In any form or shape?
Thanks.
In Microsoft Visual Studio you are able to write an implementation of IVsSingleFileGenerator.
Which is then used as custom tool to generate files at design time.
Maybe there is a similar feature in monodevelop.

Generating classes in Visual Studio. Advice needed on approach

Not sure the best way to achieve this and I would like your input.
I would like to generate a View - a ViewModel and another couple of classes.
I don't want to generate a project but just some classes.
Implementing the IWizard can you generate more than one class at one time?
Ideally I would like the user to click on a template in visual studio ,input some names etc... and generate this 4-5 classes for them.
What is the best to achieve this? Any links or suggestions on approach?
Thanks.
I would suggest using a T4 template. The engine's built right in to Visual Studio 2010, and there's a good free editor you can get through the Extension Manager (Tools > Extension Manager > Online > Search for "tangible T4").
As for how to code the templates, here's a good blog post on it which will get you started:
http://www.olegsych.com/2007/12/text-template-transformation-toolkit/
There's some info in MSDN too: http://msdn.microsoft.com/en-us/library/bb126445.aspx

can I execute an aspx file in a class library and get the result as a string?

I have an c# Class Library where I need some dynamic template based text.
Instead of inventing my own template parser I thought I could create an aspx file in my project that is executed at runtime and, instead of viewing the output in a browser, I want a StreamReader or string object that holds the result.
Is that possible? And if yes, how do I do this?
You're going to struggle more than is necessary with this approach. You'd need an ASP.NET host like IIS.
Personally, I'd recommend an existing template processor. I've heard (on a Hanselminutes or DotNetRocks podcast, I think) that you might even be able to host the T4 system in your application. I'll have a look and see if I've remembered that correctly.
Update
Here's a link on hosting T4 templating in your application.
ASP.Net is designed to be run in a web server engine - you would also have to deploy this to make it work.
Calling ASPX Pages from a Library would be possible (see Cassini WebServer) but I would recommend another tool:
http://www.codeproject.com/KB/cs/T4BasedCodeGenerator.aspx
We use it in our Project - slightly adapted for our needs

Categories

Resources