Click here to Skip to main content
15,896,111 members
Articles / Web Development / ASP.NET

How To Implement A Generic Entity List Repository And Business Logic For SharePoint 2010 Using The T4 Templating Engine

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
8 Aug 2010CPOL8 min read 42.7K   320   16  
This article describes how to implement a generic, extensible entity list repository and business logic for SharePoint 2010 using the T4 templating engine (Text Template Transformation Toolkit).
//
// Parago Media GmbH & Co. KG, Jürgen Bäurle (jbaurle@parago.de)
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//
<#@ template language="C#v3.5" debug="true" hostspecific="true" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="Microsoft.SharePoint" #>
<#@ assembly name="$(SolutionDir)MailTemplate.T4\bin\MailTemplate.T4.dll" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.Xml.Schema" #>
<#@ import namespace="Microsoft.SharePoint.Utilities" #>
<#@ import namespace="Parago.SharePoint.Samples" #>
<#

//System.Diagnostics.Debugger.Launch();
//System.Diagnostics.Debugger.Break();

var fileNames = new string[] { "MailTemplateContentType.xml" };
var listName = "MailTemplates";

var th = new TemplateHelper((IServiceProvider)Host, Host.TemplateFile);
var rootNamespace = th.GetRootNamespace();
var project = th.GetContainingProject(fileNames[0]);
var files = th.GetProjectItems(project, fileNames);
var contenTypes = files.Select(f => th.GetContentTypeInfo(f.get_FileNames(0)));

#>
// Auto-Generated: <#= DateTime.Now #>
using System;   
using System.Runtime.CompilerServices;
using Microsoft.SharePoint;

namespace <#= rootNamespace #>
{
<#
foreach(var contenType in contenTypes)
{
	var contentTypeName = th.ConvertNameToValidIdentifier(contenType.Name);
#>
	[CompilerGenerated]
	public partial class <#= contentTypeName #> 
	{
<#
foreach(var field in contenType.Fields)
{
	var typeName = th.GetCSharpTypeName(field.Type);
#>
		[FieldID("<#= field.ID #>")] public <#= typeName #> <#= field.Name #> { get; set; }
<#
}
#>		
		protected override string AssociatedList { get { return Lists.<#= listName #>; } }
		protected override SPContentTypeId AssociatedContentTypeID { get { return ContentTypes.<#= contentTypeName #>.ID; } }
	}
<#
}
#>
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
I’m a software developer based in Germany.

Homepage

Comments and Discussions