一直以爲CodeSmith是個好東西,最近正好有點時間來研究下,其實之前也想學習怎麼用,在博客園搜一下有不少介紹CodeSmith的文章,我就收藏過一個寫得很詳細的http://terrylee.cnblogs.com/archive/2005/12/28/306254.aspx,一看裏面文章這麼多,一篇一篇去學,瞬間以爲很難有木有?因而就放棄了,想着之後有時間再慢慢看,長此以往就忘了,後來想起來又打開這個收藏,發現仍是不想看,又放棄了。放在收藏裏的東西並非本身的東西,只有真正本身學過的纔是本身的東西。程序員
藉此來談一下程序員的學習方法。固然這是個人一家之言。若有雷同,不勝榮幸。ide
想學一個新的技術,最好的方法莫過於看官方文檔,外加官方的例子。學習
就拿CodeSmith來講,裝完軟件後,從開始菜單打開第一個選項就是文檔。地址:https://codesmith.atlassian.net/wiki/display/Generator/Welcome+to+CodeSmith+Generatorui
前面的介紹神馬的就不用看了,從Introduction and Tutorials-->Tutorials-->Getting Started 開始一頁一頁往下看,每頁的內容都很短,關鍵地方還有圖片,比起別人寫的長篇文章來講好懂多了(並不是別人寫的文章很差,相反他寫得很好,只是我一看滿屏的文字就眼暈)。跟着文檔學,很容易就明白了是怎麼回事,這就是學習的技巧。特別是國外的開源項目,通常都會提供文檔,有些會提供實例下載,如同個人上一篇文章微軟企業庫就提供了例子。spa
這也是我作了幾個項目總結出來的方法,別的很少說了,省得文章冗繁,各位看官不愛看了。.net
順便附上一段代碼,由於CodeSmith官方文檔在這一篇用的是VB,我改爲了C#的code
<%@ Template Language="C#" TargetLanguage="Text" Debug="False" %> <%@ Property Name="InitialState" Type="StateEnum" Category="Options" Default="STARTED" Description="" %> <%@ Property Name="Authentication" Type="AuthenticationEnum" Category="Options" Default="INTEGRATED" Description="Authentication method." %> <%@ Property Name="Port" Type="PortsEnum" Category="Options" Default="CLEAR" Description="Port to use." %> <script runat="template"> public enum StateEnum { STARTED, STOPPED, DISABLED } public enum AuthenticationEnum { BASIC, DIGEST, NTLM, KERBEROS, INTEGRATED } public enum PortsEnum { CLEAR, SSL } public string GetState(StateEnum state) { switch (state) { case StateEnum.STARTED: return "STARTED"; case StateEnum.STOPPED: return "STOPED"; case StateEnum.DISABLED: return "DISABLED"; default: return "STARTED"; } } public string GetAuthentication(AuthenticationEnum state) { switch (state) { case AuthenticationEnum.BASIC: return "BASIC"; case AuthenticationEnum.DIGEST: return "DIGEST"; case AuthenticationEnum.NTLM: return "NTLM"; case AuthenticationEnum.KERBEROS: return "KERBEROS"; case AuthenticationEnum.INTEGRATED: return "INTEGRATED"; default: return "BASIC"; } } public string GetPort(PortsEnum state) { switch (state) { case PortsEnum.CLEAR: return "CLEAR"; case PortsEnum.SSL: return "SSL"; default: return "CLEAR"; } } </script> CREATE PROC dbo.PersonAddressTypeProc AS SELECT AddressTypeID, Name, rowguid, ModifiedDate FROM Person.AddressType GO CREATE ENDPOINT GetAddressType STATE = <%=GetState(InitialState) %> AS HTTP ( PATH = '/AddressType', AUTHENTICATION = (<%=GetAuthentication(Authentication) %>), PORTS = (<%=GetPort(Port) %>), SITE = 'localhost' ) FOR SOAP ( WEBMETHOD 'AddressTypeList' (NAME='AdventureWorks.dbo.PersonAddressTypeProc'), BATCHES = DISABLED, WSDL = DEFAULT, DATABASE = 'AdventureWorks', NAMESPACE = 'http://AdventureWorks/AddressType' ) GO