Codesmith templates try to understand

Source: Internet
Author: User

1. I was very excited when I first found a regular expression on the Internet!

Regular Expression
Public String makeplural (string name)
{
RegEx plural1 = new RegEx ("(? < Keep > [^ Aeiou]) y $ ");
RegEx plural = new RegEx ("(? < Keep > [Aeiou] Y) $ ");
RegEx plur_3 = new RegEx ("(? < Keep > [Sxzh]) $ ");
RegEx plural4 = new RegEx ("(? < Keep > [^ Sxzhy]) $ ");

If (plural1.ismatch (name ))
Return plural1.replace (name, "$ {keep} ies ");
Else if (plural2.ismatch (name ))
Return plural2.replace (name, "$ {keep} s ");
Else if (plural3.ismatch (name ))
Return plural3.replace (name, "$ {keep} es ");
Else if (plural4.ismatch (name ))
Return plural4.replace (name, "$ {keep} s ");

Return name;
}

Public String makesingle (string name)
{< br> RegEx plural1 = new RegEx ("(? keep > [^ aeiou]) ies $");
RegEx plural = new RegEx ("(? keep > [aeiou] Y) S $");
RegEx plur_3 = new RegEx ("(? keep > [sxzh]) es $ ");
RegEx plural4 = new RegEx ("(? keep > [^ sxzhyu]) S $");

If (plural1.ismatch (name ))
Return plural1.replace (name, "$ {keep} y ");
Else if (plural2.ismatch (name ))
Return plural2.replace (name, "$ {keep }");
Else if (plural3.ismatch (name ))
Return plural3.replace (name, "$ {keep }");
Else if (plural4.ismatch (name ))
Return plural4.replace (name, "$ {keep }");

Return name;
}

2. Then I found a better method in the instructor template.

Method in the template

code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> Public String gettablename (tableschema table, bool plural)
{< br> string entityname = table. name;
If (plural)
{< br> entityname = stringutil. toplural (entityname);
}< br> else
{< br> entityname = stringutil. tosingular (entityname);
}< br>
return entityname;
}

3. modified the template http://www.namipan.com/downfile/Templates.rar/6a8380d9284d2b9d2b181a843c4a5053201d56079e550000 after the complex number

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.