usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Text.RegularExpressions;namespacetestpro{ Public Partial classCaseWhenSqlGeneration:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) { } protected voidBtnok_click (Objectsender, EventArgs e) { stringEnumstring = This. TxtEnum.Text.Trim (). Replace ("\ r \ n",""); BOOLUsemark = This. chkusemark.enabled; stringresult =string. Empty; List<EnumInfo> Enuminfos =NewList<enuminfo>(); stringRegstring ="(?:(?:\ \s*///\\s*<summary>) \\s*///\\s* (? <mark>[\\s]*?) (?:\ \s*///\\s*</summary>) *\\s* ((? <key>[\\s]+) \\s*=\\s* (? <value>[\\d]+) )"; Regex regex=NewRegex (regstring, Regexoptions.none); MatchCollection matchs=regex. Matches (enumstring); foreach(Match matchinchmatchs) {Enuminfos.add (NewEnuminfo {Mark= match. groups["Mark"]. Value, Key= match. groups["Key"]. Value, Value= match. groups["value"]. Value}); } foreach(varIteminchEnuminfos) { if( This. chkusemark.checked) {Result+=string. Format ("\ r \ n when {0} then ' {1} '", item. Value,string. IsNullOrEmpty (item. Mark)?item. Key:item. Mark); } Else{result+=string. Format ("\ r \ n when {0} then ' {1} '", item. Value, item. Key); } } if(Enuminfos! =NULL) {result + ="\ r \ n Else ' unknown enum ' end"; } This. Txtresult.text =result; } } Public classEnuminfo { Public stringMark {Get;Set; } Public stringKey {Get;Set; } Public stringValue {Get;Set; } }}
To generate an Case-when-then statement from an enumeration definition in SQL