示例#1
0
        public ScopeExtension SetExtension(ContextId languageContextId, ScopeExtension extension) {
            ContractUtils.RequiresNotNull(extension, "extension");

            if (languageContextId.Id >= _extensions.Length) {
                Array.Resize(ref _extensions, languageContextId.Id + 1);
            }

            ScopeExtension original = Interlocked.CompareExchange(ref _extensions[languageContextId.Id], extension, null);
            return original ?? extension;
        }
示例#2
0
        /// <summary>
        /// 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.
        /// </summary>
        public ScopeExtension SetExtension(ContextId languageContextId, ScopeExtension extension) {
            ContractUtils.RequiresNotNull(extension, "extension");

            lock (_extensions) {
                if (languageContextId.Id >= _extensions.Length) {
                    Array.Resize(ref _extensions, languageContextId.Id + 1);
                }

                return _extensions[languageContextId.Id] ?? (_extensions[languageContextId.Id] = extension);
            }
        }
示例#3
0
        /// <summary>
        /// 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.
        /// </summary>
        public ScopeExtension SetExtension(ContextId languageContextId, ScopeExtension extension)
        {
            ContractUtils.RequiresNotNull(extension, "extension");

            lock (_extensions) {
                if (languageContextId.Id >= _extensions.Length)
                {
                    Array.Resize(ref _extensions, languageContextId.Id + 1);
                }

                return(_extensions[languageContextId.Id] ?? (_extensions[languageContextId.Id] = extension));
            }
        }
示例#4
0
        public ScopeExtension SetExtension(ContextId languageContextId, ScopeExtension extension)
        {
            ContractUtils.RequiresNotNull(extension, "extension");

            if (languageContextId.Id >= _extensions.Length)
            {
                Array.Resize(ref _extensions, languageContextId.Id + 1);
            }

            ScopeExtension original = Interlocked.CompareExchange(ref _extensions[languageContextId.Id], extension, null);

            return(original ?? extension);
        }
示例#5
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);
        }