Project Description
A fast and customizable way to add type to your project. You can specify property types or can use conventions. Inspired by MvcScaffolding.
Here is the simplest example from Package Manager console:

PM> Scaffold Type Person Id,FirstName,LastName,BirthDate?

Project Objectives

Scaffold .NET types with extremely easy way (at least for simple situations).

Introduction

TypeScaffolding is the NuGet package that you can use with your Visual Studio 2010 projects.
The term “Scaffolding” is used by many software technologies to mean “quickly generating a basic outline of your software that you can then edit and customise”.
This package depends on T4Scaffolding.

Installation

  1. Install Package Manager Console (if you already installed ASP.NET MVC 3 you should already able to use Package Manager Console).
  2. Install TypeScaffolding
  3. Open the Package Manager Console window using View / Other Windows / Package Manager Console menu item and enter the following: Install-Package TypeScaffolding

You cannot use "Add Library Package Reference" dialog if you not have T4Scaffolding package installed, because it contains "init.ps1" file.

Type scaffolding

Let's look again on our simplest example:

PM> Scaffold Type Person Id,FirstName,LastName,BirthDate?

Let me explain to you what each part of this command:
  • Scaffold - command from T4Scaffolding NuGet package
  • Type - short name of the TypeScaffolding.Type scaffolder
  • Person - "Model" parameter for name of the newly created class
  • Id,FirstName,LastName,BirthDate? - "Properties" parameter for the Person's properties
  • Folder - this parameter is not used here, but you can specify folder for you class with it

The output file (Person.cs) is as follows:

public class Person
{
	public int Id {get; set;}

	[MaxLength(50)]
	[Required]
	public string FirstName {get; set;}

	[MaxLength(50)]
	[Required]
	public string LastName {get; set;}

	public System.DateTime? BirthDate {get; set;}
}

Conventions

As you can see in previous example, some kind of magic happend and types were correctly specified. Of course, this achieved not by magic but by the predefined rules.
Moreover, you can override these rules. You can enter:
PM > Scaffold CustomTemplate Type TypePatterns

After this, "TypePatterns.cs.t4" file will be saved into the "CodeTemplates\Scaffolders\TypeScaffolding.Type" folder (this is standard T4Scaffolding functionality).
".t4" extension here is only for using T4Scaffolding. "TypePatterns.cs.t4" contains regular expressions for property names and you can tune these settings as you wish.

Further reading

I think these use cases are self-explained:

PM> Scaffold Type MyModel -Folder Models -Force -NoAnnotations
PM> Scaffold Type MyModel Id,Name,Test?,ParentId,TestName[99],Count?,CreatedDate Models -Force
PM> Scaffold Type MyModel Id:long,Name:string[40],Count:long? Models -Force

Let me explain to you what some parts of these commands:
  • Scaffold - command from T4Scaffolding NuGet package
  • Type - short name of the TypeScaffolding.Model scaffolder
  • MyModel - "Model" parameter for name of the newly created class
  • Id:long,Name:string40,Count:long? - "Properties" parameter for the Person's properties

Unable to cast object of type 'NuGet.SemanticVersion'

If you have this problem after installing new version of NuGet try this:
  • Uninstall NuGet
  • Install NuGet
  • Uninstall all Scaffolding packages (TypeScaffolding, T4Scaffolding...)
  • Install Scaffolding packages.

Last edited Jan 14, 2012 at 9:45 PM by OlegAxenow, version 9