ASP.NET IronPython

Using C# Dynamic to simplify ADO.NET Data Access
Recently, I started playing around with C# dynamic, and blogged how it could be used to call static class members late bound .  Today, I was talking to Phil Haack , who I think had talked to ScottGu , and he mentioned that it would be cool to use dynamic to simplify data access when you work directly with SQL query.  So I thought I’d play around with that, and it didn’t take much code to make it work nicely. So the scenario is that you’re not using any fancy O/R mapper like LINQ to SQL or Entity Framework, but you’re directly using ADO.NET to execute raw SQL commands.  It’s not something that I would personally do, but there are a lot of folks who prefer this over the higher level data access layers. So let’s look at an example...
Using C# dynamic to call static members
By now, you’ve probably heard that C# 4.0 is adding support for the dynamic keyword, which introduces some aspects of dynamic languages to C#.  I had not had a chance to really try it, but recently I was reading Bertrand Le Roy’s post on the topic, and was sort of looking for a good opportunity to use it. Today, I found a scenario which I thought it would work great for, but it turned out not to be supported out of the box! The scenario is to call static class members using dynamic.  That probably sounds crazy, so let’s look at an example.  Say you have these two classes: public class Foo1 { public static string TransformString(string s) { return s.ToLower(); } public static string MyConstant { get { return "Constant from...
T4MVC 2.4.04 update: MVC 2 support, new settings, cleanup, fixes
To get the latest build of T4MVC: Go to download page on CodePlex   Though I haven’t blogged for a while about T4MVC, I’ve been making a few minor updates and only sent notification via Twitter.  Now, I have a few things that are worth discussing in a little more detail.  Note that you can see the complete list of changes from version to version in the readme.txt file that comes with it.  BTW, I used to have all this revision information directly in the .tt file, but it was getting a little long so I moved it to the readme. The changes described below were added between version 2.4.00 and 2.4.04.   MVC 2 Preview 2 support The most interesting things to many people is that I just made a fix to allow T4MVC to work on MVC...
T4MVC 2.4 updates: settings file, sub view folders, ActionName support and more
To get the latest build of T4MVC: Go to download page on CodePlex This post is a continuation of various previous posts on the T4MVC template for ASP.NET MVC: A new and improved ASP.NET MVC T4 template The MVC T4 template is now up on CodePlex T4MVC 2.2 update: Routing, Forms, DI container, fixes I last blogged about version 2.2, and there have been a number of changes since that (you can get the full history at the top of the T4MVC.tt file).  This post describes some of those changes.   T4MVC now uses a separate settings file Previously, if you wanted to customize T4MVC, you’d have to change T4MVC.tt directly.  This is fine until you want to grab the next build, and have to hand merge the changes. Instead, it is now using a separate...
Using an Associated Metadata Class outside Dynamic Data
A while back, I blogged about how ASP.NET Dynamic Data apps can uses an Associated Metadata class (aka a ‘buddy’ class) to add metadata attributed to properties defined in a generated class. It’s a mostly ugly thing that was made necessary by limitations of the C# and VB.NET languages: they don’t let you add attributes to properties defined in another partial class. What I didn’t mention there is that this ‘buddy’ class mechanism is actually not specific to Dynamic Data apps, and can in fact be used anywhere. Since I’ve recently heard of several cases of users trying to do something similar, I’ll describe how it’s done. If you’re familiar with TypeDescriptionProviders (which have been around since ancient times), this will look very trivial...
Two ways to use T4 templates: support code vs. one-time generation
T4 templates have proven to be useful is a whole range of scenarios, and more and more developers are finding interesting things to do with them. For the most part, all those scenarios fall under two very distinct categories: “support code” versus one-time generation.  Unlike my previous post on CodeDom vs. T4 , here we’re not talking about making a choice between two competing technologies, but simply about using T4 in the way that makes sense for a given scenario. Let’s start with a brief description of the two usage patterns: Support code : here, a T4 template generates a file that you rarely need to look at, and you should never modify.  Instead, it contains “support code” that you can code against.  A great example of this...
AspPathGuru: A little T4 love for ASP.NET WebForms
Last month , I wrote a number of posts on using T4 templates to get strong typing in ASP.NET MVC applications. The result is the T4MVC template available on CodePlex . This template has been pretty popular with many MVC users, and I received a huge amount of feedback on improving it. Most of it has been integrated into the CodePlex version (see the extensive History section in the TT file!). While T4MVC is only useful to MVC applications, someone suggested that ASP.NET WebForms applications could also benefit from some strong typing, so I put together a little T4 template that does some of that. Unlike T4MVC which tries to cover a whole range of MVC scenarios (relating to Controllers, Actions and Views), this template just does one thing: it...
T4MVC 2.2 update: Routing, Forms, DI container, fixes
To get the latest build of T4MVC: Go to download page   This post is a continuation of various recent posts, most notably: A new and improved ASP.NET MVC T4 template The MVC T4 template is now up on CodePlex First, I’d like to thank all those who are using the MVC T4 template and sent me suggestions and bug reports.  Most issues have been addressed, and most suggestions have been integrated.  I’m up to the 8th CodePlex drop, and it’s only been a week! You can see the history of changes at the top of the .tt file. Frankly, when I started playing with this, I just thought it’d be a fun thing to spend the afternoon on.  Instead, I have probably spent close to half my time working on it in the last week.  And I do have other...
The MVC T4 template is now up on CodePlex, and it does change your code a bit
Short version : the MVC T4 template (now named T4MVC) is now available on CodePlex, as one of the downloads in the ASP.NET MVC v1.0 Source page .   Poll verdict: it’s ok for T4MVC to make small changes Yesterday, I posted asking how people felt about having the template modify their code in small ways.  Thanks to all those who commented!  The fact that Scott Hanselman blogged it certainly helped get traffic there :) The majority of people thought that it was fine as long as It’s just those small changes: make classes partial and action methods virtual. Don’t mess with ‘real’ code! It asks for permission, or at least tells you what it’s doing I started looking for a way to pop up a Yes/No dialog, but ended up going with a slightly...
Mind if my MVC T4 template changes your code a bit?
When working on my MVC T4 template , I was not able to use reflection to discover the Controllers and Actions, because the code that the template generates is itself in the same assembly as the controllers.  So that causes a bit of a chicken and egg problem. Instead, I had to get out of my element and learn something I was not familiar with: the Visual Studio File Code Model API.  It’s very different from using reflection, because instead of working at the assembly level, you work at the source file level. You have to first locate the source file you want to look into.  You can then ask for the namespaces that it contains, and the classes that they contain, and finally the various members in those classes.  To be honest,...
More Posts Next page »