⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srcctrl.ascx.cs

📁 ASP.NET2.0(C#篇)经典教程的源码...本源码很好的实现了购物车....编码规范和类的设计具有很好的借鉴性!
💻 CS
📖 第 1 页 / 共 2 页
字号:

        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>'(?![^']*&quot;).*$)", 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>(&lt;!--))(?<c>(.*))(?<d>(--&gt;))(?<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>(&lt;%@))" + "(?<b>(.*))" + "(?<c>(%&gt;))";
        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>(&lt;%#))" + "(?<b>(.*))" + "(?<c>(%&gt;))";
        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>(&lt;)(?!%)(?!/?asp:)(?!/?template)(?!/?property)(?!/?wu:)(/|!)?)" + "(?<b>[^;\\s&]+)" + "(?<c>(\\s|&gt;|\\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>&lt;/?)(?<b>(asp:|template|property|wu:).*)(?<c>&gt;)?";
        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>(&lt;)(/|!|%)?)";
        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>(/|%)?(&gt;))";
        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)(?!.*&gt;)(?<a>&lt;/?)(?<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)&gt;";

        source = HttpUtility.HtmlEncode(source);
        if (Regex.IsMatch(source, searchExpr))
        {
            return true;
        }
        return false;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -