public void Encode() { IntPtr nscoding = Runtime.GetProtocol("NSCoding"); Assert.That(nscoding, Is.Not.EqualTo(IntPtr.Zero), "NSCoding"); #if !XAMCORE_2_0 // NSObject does not conform to NSCoding using (var o = new NSObject()) { Assert.False(o.ConformsToProtocol(nscoding), "NSObject/NSCoding"); using (var c = new NSCoder()) { Assert.Throws <InvalidOperationException> (delegate { o.EncodeTo(c); }, "NSObject/!NSCoding"); } } #endif // NSNumber conforms to NSCoding using (var n = new NSNumber(-1)) { Assert.True(n.ConformsToProtocol(nscoding), "NSNumber/NSCoding"); using (var d = new NSMutableData()) using (var a = new NSKeyedArchiver(d)) { n.EncodeTo(a); a.FinishEncoding(); } } }