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)); } } } }
/// <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 ); //} }
public void RegisterName(string name, object scopedElement) { if (name == null) { throw new ArgumentNullException("name"); } if (scopedElement == null) { throw new ArgumentNullException("scopedElement"); } if (name == string.Empty) { throw new ArgumentException(System.Xaml.SR.Get("NameScopeNameNotEmptyString")); } if (!NameValidationHelper.IsValidIdentifierName(name)) { throw new ArgumentException(System.Xaml.SR.Get("NameScopeInvalidIdentifierName", new object[] { name })); } if (this._underlyingNameScope != null) { this._names.Add(name); this._underlyingNameScope.RegisterName(name, scopedElement); } else if (this._nameMap == null) { this._nameMap = new HybridDictionary(); this._nameMap[name] = scopedElement; } else { object obj2 = this._nameMap[name]; if (obj2 == null) { this._nameMap[name] = scopedElement; } else if (scopedElement != obj2) { throw new ArgumentException(System.Xaml.SR.Get("NameScopeDuplicateNamesNotAllowed", new object[] { name })); } } }