srcctrl.ascx.cs
来自「ASP.NET2.0(C#篇)经典教程的源码...本源码很好的实现了购物车...」· CS 代码 · 共 413 行 · 第 1/2 页
CS
413 行
langMatch = Regex.Match(sourceLine, "(?i)<%@\\s*WebService\\s*.*Language\\s*=\\s*\"?(?<lang>[^\"]+)\"?");
if (langMatch.Success)
{
return langMatch.Groups["lang"].ToString();
}
return defLang;
}
string FixCSLine(string sourceLine)
{
if (sourceLine == null)
return null;
sourceLine = Regex.Replace(sourceLine, "(?i)(\\t)", " ");
sourceLine = HttpUtility.HtmlEncode(sourceLine);
//TODO: keywords to come from external displayFile
String[] keywords = new String[]
{"private", "protected", "public", "namespace", "class", "break",
"for", "if", "else", "while", "switch", "case", "using",
"return", "null", "void", "int", "bool", "string", "float",
"this", "new", "true", "false", "const", "static", "base",
"foreach", "in", "try", "catch", "finally", "get", "set", "char", "default",
"partial"};
String CombinedKeywords = "(?<keyword>" + String.Join("|", keywords) + ")";
sourceLine = Regex.Replace(sourceLine, "\\b" + CombinedKeywords + "\\b(?<!//.*)", TAG_FNTBLUE + "${keyword}" + TAG_EFONT);
sourceLine = Regex.Replace(sourceLine, "(?<comment>//.*$)", TAG_FNTGRN + "${comment}" + TAG_EFONT);
return sourceLine;
}
string FixJSLine(string sourceLine)
{
if (sourceLine == null)
return null;
sourceLine = Regex.Replace(sourceLine, "(?i)(\\t)", " ");
sourceLine = HttpUtility.HtmlEncode(sourceLine);
//TODO: keywords to come from external displayFile
String[] keywords = new String[]
{"private", "protected", "public", "namespace", "class", "var",
"for", "if", "else", "while", "switch", "case", "using", "get",
"return", "null", "void", "int", "string", "float", "this", "set",
"new", "true", "false", "const", "static", "package", "function",
"internal", "extends", "super", "import", "default", "break", "try",
"catch", "finally" };
String CombinedKeywords = "(?<keyword>" + String.Join("|", keywords) + ")";
sourceLine = Regex.Replace(sourceLine, "\\b" + CombinedKeywords + "\\b(?<!//.*)", TAG_FNTBLUE + "${keyword}" + TAG_EFONT);
sourceLine = Regex.Replace(sourceLine, "(?<comment>//.*$)", TAG_FNTGRN + "${comment}" + TAG_EFONT);
return sourceLine;
}
string FixVBLine(string sourceLine)
{
if (sourceLine == null)
return null;
sourceLine = Regex.Replace(sourceLine, "(?i)(\\t)", " ");
sourceLine = HttpUtility.HtmlEncode(sourceLine);
//TODO: keywords to come from external displayFile
String[] keywords = new String[]
{"Private", "Protected", "Public", "End Namespace", "Namespace",
"End Class", "Exit", "Class", "Goto", "Try", "Catch", "End Try",
"For", "End If", "If", "Else", "ElseIf", "Next", "While", "And",
"Do", "Loop", "Dim", "As", "End Select", "Select", "Case", "Or",
"Imports", "Then", "Integer", "Long", "String", "Overloads", "True",
"Overrides", "End Property", "End Sub", "End Function", "Sub", "Me",
"Function", "End Get", "End Set", "Get", "Friend", "Inherits",
"Implements","Return", "Not", "New", "Shared", "Nothing", "Finally",
"False", "Me", "My", "MyBase",
"Partial", "Using"};
String CombinedKeywords = "(?<keyword>" + String.Join("|", keywords) + ")";
sourceLine = Regex.Replace(sourceLine, "(?i)\\b" + CombinedKeywords + "\\b(?<!'.*)", TAG_FNTBLUE + "${keyword}" + TAG_EFONT);
sourceLine = Regex.Replace(sourceLine, "(?<comment>'(?![^']*").*$)", TAG_FNTGRN + "${comment}" + TAG_EFONT);
return sourceLine;
}
string FixAspxLine(string sourceLine)
{
string searchExpr; // search string
string replaceExpr; // replace string
if ((sourceLine == null) || (sourceLine.Length == 0))
return sourceLine;
// Search for \t and replace it with 4 spaces.
sourceLine = Regex.Replace(sourceLine, "(?i)(\\t)", " ");
sourceLine = HttpUtility.HtmlEncode(sourceLine);
// Single line comment or #include references.
searchExpr = "(?i)(?<a>(^.*))(?<b>(<!--))(?<c>(.*))(?<d>(-->))(?<e>(.*))";
replaceExpr = "${a}" + TAG_FNTGRN + "${b}${c}${d}" + TAG_EFONT + "${e}";
if (Regex.IsMatch(sourceLine, searchExpr))
return Regex.Replace(sourceLine, searchExpr, replaceExpr);
// Colorize <%@ <type>
searchExpr = "(?i)" + "(?<a>(<%@))" + "(?<b>(.*))" + "(?<c>(%>))";
replaceExpr = "<font color=blue><b>${a}${b}${c}</b></font>";
if (Regex.IsMatch(sourceLine, searchExpr))
sourceLine = Regex.Replace(sourceLine, searchExpr, replaceExpr);
// Colorize <%# <type>
searchExpr = "(?i)" + "(?<a>(<%#))" + "(?<b>(.*))" + "(?<c>(%>))";
replaceExpr = "${a}" + "<font color=red><b>" + "${b}" + "</b></font>" + "${c}";
if (Regex.IsMatch(sourceLine, searchExpr))
sourceLine = Regex.Replace(sourceLine, searchExpr, replaceExpr);
// Colorize tag <type>
//TODO: tags to come from external displayFile
searchExpr = "(?i)" + "(?<a>(<)(?!%)(?!/?asp:)(?!/?template)(?!/?property)(?!/?wu:)(/|!)?)" + "(?<b>[^;\\s&]+)" + "(?<c>(\\s|>|\\Z))";
replaceExpr = "${a}" + TAG_FNTMRN + "${b}" + TAG_EFONT + "${c}";
if (Regex.IsMatch(sourceLine, searchExpr))
sourceLine = Regex.Replace(sourceLine, searchExpr, replaceExpr);
// Colorize asp:|template for runat=server tags <type>
//TODO: tags to come from external displayFile
searchExpr = "(?i)(?<a></?)(?<b>(asp:|template|property|wu:).*)(?<c>>)?";
replaceExpr = "${a}<font color=blue><b>${b}</b></font>${c}";
if (Regex.IsMatch(sourceLine, searchExpr))
sourceLine = Regex.Replace(sourceLine, searchExpr, replaceExpr);
//colorize begin of tag char(s) "<","</","<%"
searchExpr = "(?i)(?<a>(<)(/|!|%)?)";
replaceExpr = TAG_FNTBLUE + "${a}" + TAG_EFONT;
if (Regex.IsMatch(sourceLine, searchExpr))
sourceLine = Regex.Replace(sourceLine, searchExpr, replaceExpr);
// Colorize end of tag char(s) ">","/>"
searchExpr = "(?i)(?<a>(/|%)?(>))";
replaceExpr = TAG_FNTBLUE + "${a}" + TAG_EFONT;
if (Regex.IsMatch(sourceLine, searchExpr))
sourceLine = Regex.Replace(sourceLine, searchExpr, replaceExpr);
return sourceLine;
}
bool IsScriptBlockTagStart(String source)
{
if (Regex.IsMatch(source, "<script.*runat=\"?server\"?.*>"))
{
return true;
}
if (Regex.IsMatch(source, "(?i)<%@\\s*WebService"))
{
return true;
}
return false;
}
bool IsScriptBlockTagEnd(String source)
{
if (Regex.IsMatch(source, "</script.*>"))
{
return true;
}
return false;
}
bool IsMultiLineTagStart(String source)
{
//TODO: tags to come from external displayFile
String searchExpr = "(?i)(?!.*>)(?<a></?)(?<b>(asp:|template|property|wu:).*)";
source = HttpUtility.HtmlEncode(source);
if (Regex.IsMatch(source, searchExpr))
{
return true;
}
return false;
}
bool IsMultiLineTagEnd(String source)
{
String searchExpr = "(?i)>";
source = HttpUtility.HtmlEncode(source);
if (Regex.IsMatch(source, searchExpr))
{
return true;
}
return false;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?