/// <summary> /// Adds a Namespace at the Current Nesting Level /// </summary> /// <param name="prefix">Prefix</param> /// <param name="uri">Namespace URI</param> public void AddNamespace(string prefix, Uri uri) { NestedMapping mapping = new NestedMapping(prefix, uri, this._level); if (!this._prefixes.ContainsKey(uri.GetEnhancedHashCode())) this._prefixes.Add(uri.GetEnhancedHashCode(), new List<NestedMapping>()); if (this._uris.ContainsKey(prefix)) { //Is it defined on the current nesting level? if (this._uris[prefix].Any(m => m.Level == this._level)) { //If it is then we override it this._uris[prefix].RemoveAll(m => m.Level == this._level); this._prefixes[uri.GetEnhancedHashCode()].RemoveAll(m => m.Level == this._level); this._uris[prefix].Add(mapping); this._prefixes[uri.GetEnhancedHashCode()].Add(mapping); this.RaiseNamespaceModified(prefix, uri); } else { //If not we simply add it this._uris[prefix].Add(mapping); this._prefixes[uri.GetEnhancedHashCode()].Add(mapping); this.RaiseNamespaceAdded(prefix, uri); } } else { //Not yet defined so add it this._uris.Add(prefix, new List<NestedMapping>()); this._uris[prefix].Add(mapping); this._prefixes[uri.GetEnhancedHashCode()].Add(mapping); this.RaiseNamespaceAdded(prefix, uri); } }
/// <summary> /// Adds a Namespace at the Current Nesting Level. /// </summary> /// <param name="prefix">Prefix.</param> /// <param name="uri">Namespace URI.</param> public void AddNamespace(string prefix, Uri uri) { if (uri == null) { throw new ArgumentNullException("Cannot set a prefix to the null URI"); } NestedMapping mapping = new NestedMapping(prefix, uri, _level); if (!_prefixes.ContainsKey(uri.GetEnhancedHashCode())) { _prefixes.Add(uri.GetEnhancedHashCode(), new List <NestedMapping>()); } if (_uris.ContainsKey(prefix)) { // Is it defined on the current nesting level? if (_uris[prefix].Any(m => m.Level == _level)) { // If it is then we override it _uris[prefix].RemoveAll(m => m.Level == _level); _prefixes[uri.GetEnhancedHashCode()].RemoveAll(m => m.Level == _level); _uris[prefix].Add(mapping); _prefixes[uri.GetEnhancedHashCode()].Add(mapping); RaiseNamespaceModified(prefix, uri); } else { // If not we simply add it _uris[prefix].Add(mapping); _prefixes[uri.GetEnhancedHashCode()].Add(mapping); RaiseNamespaceAdded(prefix, uri); } } else { // Not yet defined so add it _uris.Add(prefix, new List <NestedMapping>()); _uris[prefix].Add(mapping); _prefixes[uri.GetEnhancedHashCode()].Add(mapping); RaiseNamespaceAdded(prefix, uri); } }
/// <summary> /// Adds a Namespace at the Current Nesting Level /// </summary> /// <param name="prefix">Prefix</param> /// <param name="uri">Namespace URI</param> public void AddNamespace(string prefix, Uri uri) { NestedMapping mapping = new NestedMapping(prefix, uri, this._level); if (!this._prefixes.ContainsKey(uri.GetEnhancedHashCode())) { this._prefixes.Add(uri.GetEnhancedHashCode(), new List <NestedMapping>()); } if (this._uris.ContainsKey(prefix)) { //Is it defined on the current nesting level? if (this._uris[prefix].Any(m => m.Level == this._level)) { //If it is then we override it this._uris[prefix].RemoveAll(m => m.Level == this._level); this._prefixes[uri.GetEnhancedHashCode()].RemoveAll(m => m.Level == this._level); this._uris[prefix].Add(mapping); this._prefixes[uri.GetEnhancedHashCode()].Add(mapping); this.RaiseNamespaceModified(prefix, uri); } else { //If not we simply add it this._uris[prefix].Add(mapping); this._prefixes[uri.GetEnhancedHashCode()].Add(mapping); this.RaiseNamespaceAdded(prefix, uri); } } else { //Not yet defined so add it this._uris.Add(prefix, new List <NestedMapping>()); this._uris[prefix].Add(mapping); this._prefixes[uri.GetEnhancedHashCode()].Add(mapping); this.RaiseNamespaceAdded(prefix, uri); } }