相关疑难解决方法(0)

理解开放封闭原则

当我遇到以下代码时,我正在重构一个简单的脚本文件解析器的旧代码:

StringReader reader = new StringReader(scriptTextToProcess);
StringBuilder scope = new StringBuilder();
string line = reader.ReadLine();
while (line != null)
{
    switch (line[0])
    {
        case '$':
            // Process the entire "line" as a variable, 
            // i.e. add it to a collection of KeyValuePair.
            AddToVariables(line);
            break;
        case '!':
            // Depending of what comes after the '!' character, 
            // process the entire "scope" and/or the command in "line".
            if (line == "!execute")
                ExecuteScope(scope);
            else if (line.StartsWith("!custom_command"))
                RunCustomCommand(line, scope);
            else if …
Run Code Online (Sandbox Code Playgroud)

c# parsing open-closed-principle

11
推荐指数
1
解决办法
4345
查看次数

标签 统计

c# ×1

open-closed-principle ×1

parsing ×1