コード例 #1
0
        public void RegisterName(string name, object scopedElement)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (scopedElement == null)
            {
                throw new ArgumentNullException(nameof(scopedElement));
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString));
            }

            if (!NameValidationHelper.IsValidIdentifierName(name))
            {
                throw new ArgumentException(SR.Get(SRID.NameScopeInvalidIdentifierName, name));
            }

            if (_underlyingNameScope != null)
            {
                _names.Add(name);
                _underlyingNameScope.RegisterName(name, scopedElement);
            }
            else
            {
                if (_nameMap == null)
                {
                    _nameMap       = new HybridDictionary();
                    _nameMap[name] = scopedElement;
                }
                else
                {
                    object nameContext = _nameMap[name];

                    if (nameContext == null)
                    {
                        _nameMap[name] = scopedElement;
                    }
                    else if (scopedElement != nameContext)
                    {
                        throw new ArgumentException(SR.Get(SRID.NameScopeDuplicateNamesNotAllowed, name));
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Register Name-Object Map
        /// </summary>
        /// <param name="name">name to be registered</param>
        /// <param name="scopedElement">object mapped to name</param>
        public void RegisterName(string name, object scopedElement)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (scopedElement == null)
            {
                throw new ArgumentNullException(nameof(scopedElement));
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString));
            }

            if (!NameValidationHelper.IsValidIdentifierName(name))
            {
                throw new ArgumentException(SR.Get(SRID.NameScopeInvalidIdentifierName, name));
            }

            if (_nameMap == null)
            {
                _nameMap       = new HybridDictionary();
                _nameMap[name] = scopedElement;
            }
            else
            {
                object nameContext = _nameMap[name];
                // first time adding the Name, set it
                if (nameContext == null)
                {
                    _nameMap[name] = scopedElement;
                }
                else if (scopedElement != nameContext)
                {
                    throw new ArgumentException(SR.Get(SRID.NameScopeDuplicateNamesNotAllowed, name));
                }
            }

            //if( TraceNameScope.IsEnabled )
            //{
            //    TraceNameScope.TraceActivityItem( TraceNameScope.RegisterName,
            //                                      this,
            //                                      name,
            //                                      scopedElement );
            //}
        }