Codesmith public class Maintenance

Source: Internet
Author: User

Codesmith in the use of the process, we often appear the same method in a different page call, if we write a method on each page, then the code is very large, and if you need to change in the future in each page to modify, it is undoubtedly the life of exhausting, If there is a better way to do so. The following are available in two ways:

Method One:

1. Create the public class Comm.cs, the contents of the class are as follows:

 Public string GetData () {    return"ABC";}

2. The content of the CST file is called as follows:

<%@ codetemplate Language="C #"Targetlanguage="Text"SRC=""Inherits=""Debug="False"CompilerVersion="v3.5"Description="Template description here." %><%=GetData ()%><Scriptrunat= "template"><!--#include file="Comm.cs"  - //referencing public classes</Script>

Method Two:

1. Create the public class Comm.cs, the contents of the class are as follows:

using System; using System.Text; namespace common.data{    publicclass  Comm    {        publicstring  getData ()        {            return"ABC";        }}    }

2. The content of the CST file is called as follows:

<%@ codetemplate Language="C #"Targetlanguage="Text"SRC=""Inherits=""Debug="False"CompilerVersion="v3.5"Description="Template description here." %><%@ Assembly SRC="Comm.cs"%> <%--Reference CS--%><%@ Import Namespace="Common.data" %>  <%--Reference Namespaces--%><%=Com.getdata ()%> <Scriptrunat= "template">Comm com=NewComm ();</Script>

Codesmith public class Maintenance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.