Regular Expression is used to generate static Web pages in ASP. NET.

Source: Internet
Author: User
Static void main (){
// Create proxy and request a service
// Proxy = new proxy ();
// Proxy. Request ();
// Wait for user
Generationstaticpage P = new generationstaticpage ();
String pagecontent = P. generationpage ();
Console. Write (pagecontent );
Console. Read ();

}
Public class generationstaticpage
{
# Region attributes
Public String membername
{
Get
{
Return "vodgo ";
}
Set
{
//
}

}
Public String meetingname
{
Get
{
Return "productor page ";
}
Set
{
//
}

}

Public String roomname
{
Get
{
Return "24-1 ";
}
Set
{
//
}

}

Public String begintime
{
Get
{
Return "12:01:29 ";
}
Set
{
//
}

}
# Endregion

Public String generationpage ()
{

// read the template content (write the method yourself)
string content = "Hello ,#? Membername? # Attend the meeting :#? Meetingname? #. Location :#? Roomname? #. Time :#? Begintime? #. ";
stringbuilder builder = new stringbuilder (content);
string pattern = @"#\? (? 'Properties' \ s + ?) \? # ";
return RegEx. Replace (content, pattern, new matchevaluator (regexmatchevaluation), regexoptions. explicitcapture);
}

Private string regexmatchevaluation (match)
{
// Get the property name (named group of the RegEx)
String propertyname = match. Groups ["property"]. value;

// Try to get a property handle from the Business Object
Propertyinfo Pi = This. GetType (). getproperty (propertyname );

// Do not replace anything if no such property exists
If (Pi = NULL)
{
Return match. value;
}

// Return the property value
Object propertyvalue = pi. getvalue (this, null );
If (propertyvalue! = NULL)
{
Return propertyvalue. tostring ();
}
Else
{
Return string. empty;
}
}

}
Compare template content:
Hi ,#? Membername? # Attend the meeting :#? Meetingname? #. Location :#? Roomname? #. Time :#? Begintime? #.
Running result:
Hello, vodgo. Please attend the meeting: productor page. Location: 24-1. Time: 2007-12-1 12:01:29.

Related Article

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.