[求助]怎样自定义一个新建类的代码模板? 
在一个项目中选择“项目->添加类”时,输入“class1.cs”,会自动生成下面的代码: using System; namespace <项目名称> 

   /// <summary> 
   /// Class1 的摘要说明。 
   /// </summary> 
   public class Class1 
   { 
      public Class1() 
      { 
         // 
         // TODO: 在此处添加构造函数逻辑 
         // 
      } 
   } 
} 怎么才能重新定义这个类的模板(或者能在“添加新项”对话框中增加一个新的模板),加上我自己的特定内容呢?比如: //----- author: <> --------- 
//----- date: <>--------- 
using System; namespace <项目名称> 

   /// <summary> 
   /// Class1 的摘要说明。 
   /// </summary> 
   public class Class1 
   { 
      public Class1() 
      { 
         // 
         // TODO: 在此处添加构造函数逻辑 
         // 
      } 
   } 

解决方案 »

  1.   

    1、在你的项目中新建立你的模板类2、点击菜单:file->Export Template
       选择Item Template——选择你要做模板的类——然后按向导一步一步完成。完成后你在项目中添加item的时候,会在最下面的My Templates中看到你刚建的模板类
      

  2.   

    BearRui(AK-47) ( ) 信誉:110 
    回符的好:)
      

  3.   

    谢谢
    现在有个问题是:我这个建好模板后,我希望每次加载模板时能够动态的获得author,date的信息,如下
    //----- author: <zhangsu> --------- 
    //----- date: <8-20>--------- 
    这个信息应该是从操作系统,或者.config配置文件,或者是从vss中获得。
    请问:这种在模板中动态的读取数据的功能怎么实现? 
    谢谢
      

  4.   

    觉得楼主这个要求可以使用IDE的宏来操作,就是打开宏代码编辑器,编写一个使用于IDE的宏命令,每次需要插入这些注释的时候,可以使用一个快捷键运行已定义好的宏,从而自动的取出信息并添加到当前代码中。
      

  5.   

    就是希望在添加新项时,能够及时加载当前用户的信息,比如一个vss的用户名
    不知道net2005是否支持这个的功能,或者各位大侠是否能够找出实现这个功能的方法
    谢谢
      

  6.   

    请问hbxtlhx:
    你说的方法应该怎么实现 如何操作“使用IDE的宏来操作,就是打开宏代码编辑器,编写一个使用于IDE的宏命令” 希望多加指点 谢谢
      

  7.   

    /// <summary> 
    /// Class1 的摘要说明。 
    /// </summary> 
    public class Class1 
    {
    .......
    }
    楼主说的是不是智能感应里头的注释?如果是的话,只需要在类或方法的上面用以下格式,然后调用的时候就会有提示了。
    /// <summary> 
    /// 自定义的说明.. 
    /// </summary>
      

  8.   

    http://www.microsoft.com/china/community/program/originalarticles/techdoc/netmacro.mspx
      

  9.   

    如果你只是想取用户和时间的话,用参数就可以实现了:仍然按我前面的步骤操作来创建模板,不过在你的模板类的时候这样写://----- author: <$username$> ---------
    //----- date: <$time$>--------- 
    $username$和$time$是2个参数.
      

  10.   

    NET支持的模板参数如下: 
    clrversion
     Current version of the common language runtime (CLR).
     
    GUID [1-10]
     A GUID used to replace the project GUID in a project file. You can specify up to 10 unique GUIDs (for example, guid1).
     
    itemname
     The name provided by the user in the Add New Item dialog box.
     
    machinename
     The current computer name (for example, Computer01).
     
    projectname
     The name provided by the user in the New Project dialog box.
     
    registeredorganization
     The registry key value from HKLM\Software\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization.
     
    rootnamespace
     The root namespace of the current project. This parameter is used to replace the namespace in an item being added to a project.
     
    safeitemname
     The name provided by the user in the Add New Item dialog box, with all unsafe characters and spaces removed.
     
    safeprojectname
     The name provided by the user in the New Project dialog box, with all unsafe characters and spaces removed.
     
    time
     The current time in the format DD/MM/YYYY 00:00:00.
     
    userdomain
     The current user domain.
     
    username
     The current user name.
     
    year
     The current year in the format YYYY.
     
      

  11.   

    请问“智能感应里头的注释”是指?
    “只需要在类或方法的上面用以下格式,然后调用的时候就会有提示了”
    能举个例子吗? 谢谢------------------------------------------------
    他说的是xml的注释,不是你要找的那...
    输入三个/
      

  12.   

    http://msdn2.microsoft.com/zh-cn/library/ms247069(VS.80).aspx