当前位置: 首页>>代码示例>>C#>>正文


C# Instruction.AddVariable方法代码示例

本文整理汇总了C#中Instruction.AddVariable方法的典型用法代码示例。如果您正苦于以下问题:C# Instruction.AddVariable方法的具体用法?C# Instruction.AddVariable怎么用?C# Instruction.AddVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Instruction的用法示例。


在下文中一共展示了Instruction.AddVariable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessInstruction

        private void ProcessInstruction(string instructionLine) {
            int dummy;
            if (instructionLine.StartsWith("#define ")) {
                string variableName = ParseInstructionVariable(instructionLine, 8, out dummy);
                if (variableName == null) {
                    RaiseError("Missing variable following the '#define' instruction.");
                }
                if (_definedVariables.ContainsKey(variableName)) {
                    RaiseError("Duplicate definition of variable '" + variableName + "'.");
                }

                _definedVariables[variableName] = String.Empty;
            }
            else if (instructionLine.StartsWith("#undefine ")) {
                string variableName = ParseInstructionVariable(instructionLine, 10, out dummy);

                if (variableName == null) {
                    RaiseError("Missing variable following the '#undefine' instruction.");
                }
                if (_definedVariables.ContainsKey(variableName) == false) {
                    RaiseError("The variable '" + variableName + "' has not been defined yet.");
                }

                _definedVariables.Remove(variableName);
            }
            else if (instructionLine.StartsWith("#if ")) {
                string variableName = ParseInstructionVariable(instructionLine, 4, out dummy);

                if (variableName == null) {
                    RaiseError("Missing variable following the '#if' instruction.");
                }

                Instruction instruction = new Instruction();
                _activeInstructions.Push(instruction);

                instruction.AddVariable(variableName, _definedVariables);
            }
            else if (instructionLine.StartsWith("#elseif ") ||
                     instructionLine.StartsWith("#elif ")) {
                string variableName = ParseInstructionVariable(instructionLine, 8, out dummy);
                if (variableName == null) {
                    RaiseError("Missing variable following the '#elif' instruction.");
                }

                if (_activeInstructions.Count == 0) {
                    RaiseError("Unexpected '#elif' instruction.");
                }

                Instruction currentInstruction = _activeInstructions.Peek();
                bool added = currentInstruction.AddVariable(variableName, _definedVariables);

                if (added == false) {
                    RaiseError("The specified '" + variableName + "' has already been used, or an '#else' instruction has already been specified.");
                }
            }
            else if (instructionLine.StartsWith("#else")) {
                if (_activeInstructions.Count == 0) {
                    RaiseError("Unexpected '#else' instruction.");
                }

                Instruction currentInstruction = _activeInstructions.Peek();
                bool added = currentInstruction.AddVariable(null, _definedVariables);

                if (added == false) {
                    RaiseError("Only a single '#else' instruction is allowed for a given '#if' instruction.");
                }
            }
            else if (instructionLine.StartsWith("#endif")) {
                if (_activeInstructions.Count == 0) {
                    RaiseError("Unexpected '#endif' instruction.");
                }

                _activeInstructions.Pop();
            }
        }
开发者ID:fugaku,项目名称:scriptsharp,代码行数:75,代码来源:PreprocessorTextReader.cs


注:本文中的Instruction.AddVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。