/// <summary> /// Internal Helper for the NamespaceRemoved Event which raises it only when a Handler is registered /// </summary> /// <param name="prefix">Namespace Prefix</param> /// <param name="uri">Namespace Uri</param> protected virtual void OnNamespaceRemoved(String prefix, Uri uri) { NamespaceChanged handler = this.NamespaceRemoved; if (handler != null) { handler(prefix, uri); } }
/// <summary> /// Internal Helper for the NamespaceModified Event which raises it only when a Handler is registered /// </summary> /// <param name="prefix">Namespace Prefix</param> /// <param name="uri">Namespace Uri</param> protected virtual void RaiseNamespaceModified(String prefix, Uri uri) { NamespaceChanged handler = this.NamespaceModified; if (handler != null) { handler(prefix, uri); } }
/// <summary> /// Internal Helper for the NamespaceModified Event which raises it only when a Handler is registered. /// </summary> /// <param name="prefix">Namespace Prefix.</param> /// <param name="uri">Namespace Uri.</param> protected virtual void OnNamespaceModified(string prefix, Uri uri) { NamespaceChanged handler = NamespaceModified; if (handler != null) { handler(prefix, uri); } }
public void NamespaceMapperEvent() { bool eventRaised = false; NamespaceChanged added = delegate(String prefix, Uri u) { eventRaised = true; }; NamespaceChanged changed = delegate(String prefix, Uri u) { eventRaised = true; }; NamespaceChanged removed = delegate(String prefix, Uri u) { eventRaised = true; }; NamespaceMapper nsmap = new NamespaceMapper(); nsmap.NamespaceAdded += added; nsmap.NamespaceModified += changed; nsmap.NamespaceRemoved += removed; Console.WriteLine("Trying to add the RDF Namespace, this should already be defined"); nsmap.AddNamespace("rdf", new Uri(NamespaceMapper.RDF)); Assert.False(eventRaised); eventRaised = false; Console.WriteLine(); Console.WriteLine("Trying to add an example Namespace which isn't defined"); nsmap.AddNamespace("ex", new Uri("http://example.org/")); Assert.True(eventRaised); eventRaised = false; Console.WriteLine(nsmap.GetNamespaceUri("ex").AbsoluteUri); Console.WriteLine(); Console.WriteLine("Trying to modify the example Namespace"); nsmap.AddNamespace("ex", new Uri("http://example.org/test/")); Assert.True(eventRaised); eventRaised = false; Console.WriteLine(nsmap.GetNamespaceUri("ex").AbsoluteUri); Console.WriteLine(); Console.WriteLine("Trying to remove the example Namespace"); nsmap.RemoveNamespace("ex"); Assert.True(eventRaised); eventRaised = false; Console.WriteLine(); Console.WriteLine("Trying to remove a non-existent Namespace"); nsmap.RemoveNamespace("ex"); Assert.False(eventRaised); eventRaised = false; Console.WriteLine(); Console.WriteLine("Adding some example Namespace back in again for an import test"); nsmap.AddNamespace("ex", new Uri("http://example.org/")); nsmap.AddNamespace("ns0", new Uri("http://example.org/clashes/")); Console.WriteLine("Creating another Namespace Mapper with the ex prefix mapped to a different URI"); NamespaceMapper nsmap2 = new NamespaceMapper(); nsmap2.AddNamespace("ex", new Uri("http://example.org/test/")); Console.WriteLine("Importing the new NamespaceMapper into the original"); nsmap.Import(nsmap2); Console.WriteLine("NamespaceMapper now contains the following Namespaces:"); foreach (String prefix in nsmap.Prefixes) { Console.WriteLine("\t" + prefix + " <" + nsmap.GetNamespaceUri(prefix).AbsoluteUri + ">"); } Assert.Equal(nsmap.GetNamespaceUri("ex"), new Uri("http://example.org/")); Assert.Equal(nsmap.GetNamespaceUri("ns1"), new Uri("http://example.org/test/")); }