System.Xml.Xsl.XsltOld.Compiler.InsertVariable C# (CSharp) Method

InsertVariable() private method

private InsertVariable ( VariableAction variable ) : int
variable VariableAction
return int
        internal int InsertVariable(VariableAction variable)
        {
            InputScope varScope;
            if (variable.IsGlobal)
            {
                Debug.Assert(_rootAction != null);
                varScope = _rootScope;
            }
            else
            {
                Debug.Assert(_currentTemplate != null);
                Debug.Assert(variable.VarType == VariableType.LocalVariable || variable.VarType == VariableType.LocalParameter || variable.VarType == VariableType.WithParameter);
                varScope = _scopeManager.VariableScope;
            }

            VariableAction oldVar = varScope.ResolveVariable(variable.Name);
            if (oldVar != null)
            {
                // Other variable with this name is visible in this scope
                if (oldVar.IsGlobal)
                {
                    if (variable.IsGlobal)
                    {
                        // Global Vars replace each other base on import presidens odred
                        if (variable.Stylesheetid == oldVar.Stylesheetid)
                        {
                            // Both vars are in the same stylesheet
                            throw XsltException.Create(SR.Xslt_DupVarName, variable.NameStr);
                        }
                        else if (variable.Stylesheetid < oldVar.Stylesheetid)
                        {
                            // newly defined var is more importent
                            varScope.InsertVariable(variable);
                            return oldVar.VarKey;
                        }
                        else
                        {
                            // we egnore new variable
                            return InvalidQueryKey; // We didn't add this var, so doesn't matter what VarKey we return;
                        }
                    }
                    else
                    {
                        // local variable can shadow global
                    }
                }
                else
                {
                    // Local variable never can be "shadowed"
                    throw XsltException.Create(SR.Xslt_DupVarName, variable.NameStr);
                }
            }

            varScope.InsertVariable(variable);
            return _currentTemplate.AllocateVariableSlot();
        }

Usage Example

        internal override void Compile(Compiler compiler)
        {
            this.stylesheetid = compiler.Stylesheetid;
            this.baseUri      = compiler.Input.BaseURI;
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.name, "name");


            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();

                if (this.selectKey != Compiler.InvalidQueryKey && this.containedActions != null)
                {
                    throw XsltException.Create(SR.Xslt_VariableCntSel2, this.nameStr);
                }
            }
            if (this.containedActions != null)
            {
                baseUri = baseUri + '#' + compiler.GetUnicRtfId();
            }
            else
            {
                baseUri = null;
            }

            _varKey = compiler.InsertVariable(this);
        }
All Usage Examples Of System.Xml.Xsl.XsltOld.Compiler::InsertVariable