public void Copy() { IntPtr nscopying = Runtime.GetProtocol("NSCopying"); Assert.That(nscopying, Is.Not.EqualTo(IntPtr.Zero), "NSCopying"); IntPtr nsmutablecopying = Runtime.GetProtocol("NSMutableCopying"); Assert.That(nsmutablecopying, Is.Not.EqualTo(IntPtr.Zero), "NSMutableCopying"); // NSObject does not conform to NSCopying using (var o = new NSObject()) { Assert.False(o.ConformsToProtocol(nscopying), "NSObject/NSCopying"); Assert.False(o.ConformsToProtocol(nsmutablecopying), "NSObject/NSMutableCopying"); } // NSNumber conforms to NSCopying - but not NSMutableCopying using (var n = new NSNumber(-1)) { Assert.True(n.ConformsToProtocol(nscopying), "NSNumber/NSCopying"); using (var xn = n.Copy()) { Assert.NotNull(xn, "NSNumber/Copy/NotNull"); Assert.AreSame(n, xn, "NSNumber/Copy/NotSame"); } Assert.False(n.ConformsToProtocol(nsmutablecopying), "NSNumber/NSMutableCopying"); } // NSMutableString conforms to NSCopying - but not NSMutableCopying using (var s = new NSMutableString(1)) { Assert.True(s.ConformsToProtocol(nscopying), "NSMutableString/NSCopying"); using (var xs = s.Copy()) { Assert.NotNull(xs, "NSMutableString/Copy/NotNull"); Assert.AreNotSame(s, xs, "NSMutableString/Copy/NotSame"); } Assert.True(s.ConformsToProtocol(nsmutablecopying), "NSMutableString/NSMutableCopying"); using (var xs = s.MutableCopy()) { Assert.NotNull(xs, "NSMutableString/MutableCopy/NotNull"); Assert.AreNotSame(s, xs, "NSMutableString/MutableCopy/NotSame"); } } }