as I am always use db table as source for codesmith, but currently I don't have a table definition,just class definition, for example:
public class RespObj
{
public string Status { get; set; }
public string Msg { get; set; }
public object Resp { get; set; }
public string ErrCode { get; set; }
}
above code using c#,not the db table,how to use codesmith to do this thing?
This is one of the main use cases for CodeSmith. I am writing this TEMPLATE in VB, but it can be used to generate any sort of file. Codesmith can use C#, feel free to convert this to C#, fairly straight forward exercise
The first part defines some assemblies that must be referenced. The Imports then allow the template to reference those assemblies
The Property 'SourceTable' is where the magic happens. When you compile the table the first time, hit F4 and the template properties screen will appear.
Click the elipses '...' to the right of the SourceTable line and point to your DB and table. You will need to define a new DataSource , this requires a connection string to your database.
An example is
This will get you started. In the routine DeclarationFromColumn, you will want to declare a c# type from the SQL server type.
What has worked for me is to take a complete working class that you already have, paste it into the template, and then start looking for places where you run through all the fields.
In each of those instances, write some template code to generate that list.
All of the functions need to go in the
<Script></Script>tag.