Table of contents



Installation

Go to genuilder.codeplex.com and download the Genuilder visual studio extension.

GenuilderSite.png

Run it.

GenuilderInstall.png

Restart Visual Studio, you should then see the new project item.

ProjectTemplate.png

Upgrading Genuilder

You have to uninstall the previous version of Genuilder in the Extension Manager. (In visual studio "Tools/Extension manager")

UnInstall.png

Common Features

Common features are accessible through the CommonFeature enumeration in your Genuilder project.

CommonFeaturesEnum.png

You need to run your Genuilder project each time you modify it to install or remove features from your projects.

AppConfigVerifier

The AppConfigVerifier is an integration in Genuilder of this project.
It scans all 'type=".*"' in the config file, and check if the type is referenced in the project.
The documentation can be found on CodeProject
Here is a quick example, where in the config file you misspelled the MembershipProvider type:

AppConfigVerifier-Config.jpg

Genuilder will find the error at compile time:

AppConfigVerifier-Error.jpg

You can exclude types or assemblies from the verification, just check this article

AppSettingsGenerator

This feature comes from one of my articles on CodeProject.
With it you can access to your AppSettings and ConnectionStrings in a strongly typed way.
Example, the appconfig :
AppSettingsGenerator-Config.jpg
Auto completion on AppSettings :
AppSettingsGenerator-AppSettings.jpg
Auto completion on ConnectionStrings :
AppSettingsGenerator-ConnectionStrings.jpg

EnvironmentFile

The EnvironmentFile is just a pre-processor for your config file. For example you
have this app.config with a token:
environmentfile1.jpg

You have also this EnvironmentFile.env file which is just a key=value pair list
delimited by line breaks:

environmentfile2.jpg

After compilation, the output config file (for example MyProject.exe.config) will
be:

environmentfile3.jpg

This is particulary useful when developpers in a team have not the same development environment,
they doesn't need to checkout their own version of the app.config. (The EnvironmentFile should be unique for each developer and should not be in your source control.)

If one of your fellow developer changes the config file like that:
environmentfile4.jpg

After the next Get latest version, the project will not compile because the new
token is not set in the EnvironmentFile.env:

environmentfile5.jpg

Note : this feature doesn't work for web.config files. (Don't worry .NET 4.0 is coming with a new feature for web.config files)

InterfaceExtractor

Interface extractor is a code generator which extract an interface from public members of classes and structs.
This feature is really useful when you want to create static or dynamic proxies around a service or a controller for authentication or logging for example.
I'll create an article on codeproject on a nice use case with ASP.NET MVC to control authorized access of a controller. (I have not done and I've not eat my own dog food yet... so be really careful with this feature ! ;))

For example this class :

InterfaceExtractor-Class.jpg

Will create extract this interface :

InterfaceExtractor-Interface.jpg

Note that the parameter of the ExtractInterface is optional, the default interface name is IClassName.
Also, you don't have to implement the interface on your class.

Warning : [ExtractInterface(typeof(SomeNamespace.Interface))] is currently not allowed, you cannot specify the namespace of the extracted interface... not a big deal to add though

PropertiesExtractor

As InterfaceExtractor, PropertiesExtractor is a class generator which generate a static class to access properties name in a strongly typed way.
For example this class implement INotifyPropertyChanged and do not hard code the property name with a string :

PropertiesExtractor-Class.jpg

Because PropertiesExtractor will generate this other class

PropertiesExtractor-Properties.jpg

This way if you refactor the property name, the code will break at compile time instead of during runtime.

As with InterfaceExtractor, the parameter of the ExtractProperties is optional, the default class name is ClassNameProperties.
Warning : [ExtractProperties(typeof(SomeNamespace.MyClassProperties))] is currently not allowed, you cannot specify the namespace of the extracted class properties... not a big deal to add though

StrongConfigGenerator

This feature generate a class to access to your configuration file in a strongly typed way.
If you remove a section whereas your code somewhere has a dependency on it, it will break the code at compile time instead of during the runtime.

For example for this config file :

StrongConfigGenerator-Config.jpg

You will be able to access to sections like this :

StrongConfigGenerator-Class.jpg

Extensions

Installing an extension in your project

An article have been written on codeproject to introduce the Extensibility framework of Genuilder.
To install an extension, you need to use an Extensibility Feature, add extensions and install it on the project.

Using.png

Built-in Extensions

AsyncServiceContractsExtension

This extension creates a ServiceContract given a synchronous ServiceContract, useful for Silverlight projects.
Given :
ICustomerService.png
Will generate :
ICustomerServiceAsync.png
An example is given here

StronglyTypedReflectionExtension

It generate classes to access to type's member in a strongly typed way.
Given :
Class1.png
It will generate a class to access PropertyInfo, MehtodInfo, EventInfo this way :
Class1Type.png

ProxyGeneratorExtension

The goal and usage of this Extension is explained on this codeproject's article.

XamlVerifierExtension

Shown on codeproject.

XamlResourceExtension

Shown on codeproject.

Custom Extension

Object Model

To create your own extension, you have to implement IExtension, here is the object model of Genuilder.Extensibility
ObjectModel.png

GenItems represents code files of your project, you can use ExecutionContext.CreateChild(string name) and GenItem.CreateChild(string name) to create new ones.
When you use GenItem.CreateChild, the child will be deleted when the parent is deleted.

MSBuild logging

You can easily send warning, error and info message to visual studio by using ExecutionContext.Logger and GenItem.Logger.
For example, in this example I output an error on Program.cs line 5 column 6 in Visual Studio.

MyExtension.png

Once installed on my project here is what happen at compile time :

Error.png


Debugging an Extension

You can easily debug your extensions by calling the .Build() method on your project
ExtensionDebugging.png
In this case you will be able to break in the MyExtension class to see what is going on during the build.

Easy code parsing and generation

Genuilder has a built-in object extension to easily parse CodeItems with NRefactory.

CompilationUnitExtension.png

You can use the CompilationUnit property to walk through the Abstract Syntax Tree (AST).
Or, more easily, use the Visitor pattern by implementing AbstractASTVisitor, overriding methods called during the visit of the tree, then calling CompilationUnit.Visit(visitor,null);
Take a look at the code source of ProxyGeneratorExtension.

In this example, you'll see how to use the CodeWriter class to generate readable code.
CodeWriter.png

Resharper

Currently, the intellisense of Resharper doesn't work on generated classes. But the code will compile.

Last edited Jan 20, 2012 at 9:17 AM by Slashene, version 93

Comments

No comments yet.