CodeGen
There are 6 entries for the tag
CodeGen
Download the sample source code for this post here
In this post I will attempt to describe what I learned while working out how to separate the concerns of a WCF service layer from those of a presentation layer and vice-versa while using a redistributable client assembly and NOT using client proxy code generated by Visual Studio 'Add Service Reference' or svcutil.exe.
The code and scenarios do not necessarily represent best practices and will most likely offend some purists but I do believe that the topics covered represent real world challenges and may provide some insight into some not-so-obvious aspects of...
You can find the code @ DeadSimpleDTO.codeplex.com
New in 2.01
INotifyPropertyChanged option
One-to-many and many-to-one relationships optionally rendered
Examples:
Default options: basic property bag dto
/*
DeadSimpleDTO
default options
basic property bag dto
*/
using System;
using Northwind;
namespace Northwind
{
public partial class Orders
{
#region Properties
private Int32 _orderID;
public virtual Int32 OrderID
{
get { return _orderID; }
...
In a previous post, Accessing app.config/web.config from T4 template, I provided an include template to provide access to the configuration file. In this post I present a stand-alone template, umm, template that you can stuff your own code into.
ConfigEnabledTemplate.tt
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" language="C#v3.5" debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Configuration.dll" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Configuration" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#
// <copyright file="c" company="Sky Sanders">
//
// This source is a Public Domain Dedication.
//
// http://salientt4.codeplex.com
//
// Attribution is appreciated.
//
// </copyright>
/// <summary>
/// This template can serve as a starting point for...
UPDATE: After using this code a bit more it has become apparent that the Sql2008 types are all string convertable and that Byte[] is a better choice for a generic reader implementation.
You may also handle single field UDT by getting the name of the system_type_id when is_user_defined = 1 in sys.columns.
date NULL = Nullable<DateTime>
DECLARE @current_column_type VARCHAR(30),
@current_column_nullable BIT,
@generated_property_type NVARCHAR(128)
SET @current_column_type = 'date'
SET @current_column_nullable = 1
-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DECLARE @fn_ctype_input_type NVARCHAR(128),
@fn_ctype_input_nullable BIT,
@fn_ctype_output_type NVARCHAR(128)
-- --> ConvertType Function - set input
SET @fn_ctype_input_type = @current_column_type
SET @fn_ctype_input_nullable = @current_column_nullable
-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BEGIN
SET @fn_ctype_output_type = CASE @fn_ctype_input_type
...
Code blocks in a T4 template are run in the context of the templating service and have no notion of app/web config.
Oleg Sych provides much detail on T4 Architecture.
To access configuration files in a template we have to drill down a few levels of abstraction to get a reference to the project hosting the template. From that point we can utilize classes from the Configuration namespace to closely approximate standard Configuration file behavior.
Presented here is a re-usable template, ConfigurationAccessor.tt, that can be included in a template to provide strongly typed access to the configuration file and hosting project, and...
I am working on a spike that requires fetching metadata views from Sql Server's sys and INFORMATION_SCHEMA schemas. Initially, coding a few DTO by hand was no problem but as new views are required it obviously became tedious and typo prone.
I really did not want to break out ANY ORM, I just needed to read the data and a simple reflective filler would do just fine. In any case, I found myself in a query window writing a SQL based DTO generator. It ultimately ended up including a lot of clever functionality and I will present it here but first lets start with...