SetExtension() public method

Sets the ScopeExtension to the provided value for the given ContextId. The extension can only be set once. The returned value is either the new ScopeExtension if no value was previously set or the previous value.
public SetExtension ( ContextId languageContextId, Microsoft.Scripting.Runtime.ScopeExtension extension ) : Microsoft.Scripting.Runtime.ScopeExtension
languageContextId ContextId
extension Microsoft.Scripting.Runtime.ScopeExtension
return Microsoft.Scripting.Runtime.ScopeExtension
Example #1
0
        /// <summary>
        /// Creates a new ModuleContext which is backed by the specified dictionary.
        /// </summary>
        public ModuleContext(PythonDictionary/*!*/ globals, PythonContext/*!*/ creatingContext) {
            ContractUtils.RequiresNotNull(globals, "globals");
            ContractUtils.RequiresNotNull(creatingContext, "creatingContext");

            _globals = globals;
            _pyContext = creatingContext;
            _globalScope = new Scope(globals);
            _globalContext = new CodeContext(globals, this);
            _module = new PythonModule(globals, _globalScope);
            _globalScope.SetExtension(_pyContext.ContextId, new PythonScopeExtension(_pyContext, _module, this));
        }
Example #2
0
        // TODO: remove
        public ScopeExtension EnsureScopeExtension(Scope scope)
        {
            ContractUtils.RequiresNotNull(scope, "scope");
            ScopeExtension extension = scope.GetExtension(ContextId);

            if (extension == null)
            {
                extension = CreateScopeExtension(scope);
                if (extension == null)
                {
                    throw Error.MustReturnScopeExtension();
                }
                return(scope.SetExtension(ContextId, extension));
            }

            return(extension);
        }
Example #3
0
 private Scope CreateScope()
 {
     Scope ret = new Scope(new ObjectDictionaryExpando(_dict));
     ret.SetExtension(_context.ContextId, new TotemScopeExtension(_context, ret));
     return ret;
 }