xamarin-macios/src/AddressBookUI/ABAddressFormatting.cs

42 строки
1.2 KiB
C#
Исходник Обычный вид История

2016-04-21 15:30:02 +03:00
//
// ABAddressFormatting.cs:
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright (C) 2012 Xamarin Inc. All rights reserved.
//
#nullable enable
2016-04-21 15:30:02 +03:00
using System;
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;
2016-04-21 15:30:02 +03:00
namespace AddressBookUI {
2016-04-21 15:30:02 +03:00
// http://developer.apple.com/library/ios/#DOCUMENTATION/AddressBookUI/Reference/AddressBookUI_Functions/Reference/reference.html#//apple_ref/c/func/ABCreateStringWithAddressDictionary
#if NET
[SupportedOSPlatform ("ios")]
[ObsoletedOSPlatform ("ios9.0", "Use the 'Contacts' API instead.")]
#else
[Deprecated (PlatformName.iOS, 9, 0, message: "Use the 'Contacts' API instead.")]
#endif
2016-04-21 15:30:02 +03:00
static public class ABAddressFormatting {
2016-04-21 15:30:02 +03:00
[DllImport (Constants.AddressBookUILibrary)]
static extern IntPtr /* NSString */ ABCreateStringWithAddressDictionary (IntPtr /* NSDictionary */ address, [MarshalAs (UnmanagedType.I1)] bool addCountryName);
2016-04-21 15:30:02 +03:00
static public string ToString (NSDictionary address, bool addCountryName)
{
if (address is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (address));
2016-04-21 15:30:02 +03:00
using (NSString s = new NSString (ABCreateStringWithAddressDictionary (address.Handle, addCountryName)))
return s.ToString ();
}
}
}