public static Item <object> FromDirectory(NSUrl directoryUrl, NSFileAttributes fileAttributes = null) { return(new Item <object>(directoryUrl, fileAttributes, ItemType.Directory, (attributes, data, urls) => { return urls.Select(x => { NSObject resourceObject = null; x.TryGetResource(NSUrl.IsDirectoryKey, out resourceObject); bool isDirectoryObject = false; if (resourceObject != null) { var convertedNsObject = resourceObject.ToObject(typeof(bool)); if (convertedNsObject != null) { isDirectoryObject = (bool)convertedNsObject; } } return At(x, attributes, isDirectoryObject); }).ToArray(); })); }
/// <summary> /// 将 plist 格式的 xml 内容,解析成 Newtowsoft.Json JObject 对象来访问 /// </summary> /// <param name="plist">plist 格式的 xml 内容</param> /// <returns>JObject</returns> public static JObject ParsePListToJson(string plist) { NSObject obj = XmlPropertyListParser.Parse(Encoding.UTF8.GetBytes(plist)); string json = JsonConvert.SerializeObject(obj.ToObject()); return(JsonConvert.DeserializeObject <JObject>(json)); }
public static void TestWrap() { bool bl = true; byte byt = 24; short shrt = 12; int i = 42; long lng = 30000000000L; float flt = 124.3f; double dbl = 32.0; DateTime date = new DateTime(); string strg = "Hello World"; byte[] bytes = new byte[] { (byte)0x00, (byte)0xAF, (byte)0xAF }; Object[] array = new Object[] { bl, byt, shrt, i, lng, flt, dbl, date, strg, bytes }; int[] array2 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3000 }; List <Object> list = new List <Object>(array); Dictionary <string, Object> map = new Dictionary <string, Object>(); map.Add("int", i); map.Add("long", lng); map.Add("date", date); NSObject WrappedO = NSObject.Wrap((Object)bl); Assert.True(WrappedO.GetType().Equals(typeof(NSNumber))); Assert.True(WrappedO.ToObject().Equals(bl)); WrappedO = NSObject.Wrap((Object)byt); Assert.True(WrappedO.GetType().Equals(typeof(NSNumber))); Assert.True((int)WrappedO.ToObject() == byt); WrappedO = NSObject.Wrap((Object)shrt); Assert.True(WrappedO.GetType().Equals(typeof(NSNumber))); Assert.True((int)WrappedO.ToObject() == shrt); WrappedO = NSObject.Wrap((Object)i); Assert.True(WrappedO.GetType().Equals(typeof(NSNumber))); Assert.True((int)WrappedO.ToObject() == i); WrappedO = NSObject.Wrap((Object)lng); Assert.True(WrappedO.GetType().Equals(typeof(NSNumber))); Assert.True((long)WrappedO.ToObject() == lng); WrappedO = NSObject.Wrap((Object)flt); Assert.True(WrappedO.GetType().Equals(typeof(NSNumber))); Assert.True((double)WrappedO.ToObject() == flt); WrappedO = NSObject.Wrap((Object)dbl); Assert.True(WrappedO.GetType().Equals(typeof(NSNumber))); Assert.True((double)WrappedO.ToObject() == dbl); WrappedO = NSObject.Wrap((Object)date); Assert.True(WrappedO.GetType().Equals(typeof(NSDate))); Assert.True(((DateTime)WrappedO.ToObject()).Equals(date)); WrappedO = NSObject.Wrap((Object)strg); Assert.True(WrappedO.GetType().Equals(typeof(NSString))); Assert.True(((string)WrappedO.ToObject()).Equals(strg)); WrappedO = NSObject.Wrap((Object)bytes); Assert.True(WrappedO.GetType().Equals(typeof(NSData))); byte[] data = (byte[])WrappedO.ToObject(); Assert.True(data.Length == bytes.Length); for (int x = 0; x < bytes.Length; x++) { Assert.True(data[x] == bytes[x]); } WrappedO = NSObject.Wrap((Object)array); Assert.True(WrappedO.GetType().Equals(typeof(NSArray))); Object[] objArray = (Object[])WrappedO.ToObject(); Assert.True(objArray.Length == array.Length); WrappedO = NSObject.Wrap((Object)array2); Assert.True(WrappedO.GetType().Equals(typeof(NSArray))); Assert.True(((NSArray)WrappedO).Count == array2.Length); WrappedO = NSObject.Wrap((Object)list); Assert.True(WrappedO.GetType().Equals(typeof(NSArray))); objArray = (Object[])WrappedO.ToObject(); Assert.True(objArray.Length == array.Length); WrappedO = NSObject.Wrap((Object)map); Assert.True(WrappedO.GetType().Equals(typeof(NSDictionary))); NSDictionary dict = (NSDictionary)WrappedO; Assert.True(((NSNumber)dict.ObjectForKey("int")).ToLong() == i); Assert.True(((NSNumber)dict.ObjectForKey("long")).ToLong() == lng); Assert.True(((NSDate)dict.ObjectForKey("date")).Date.Equals(date)); // TODO /* * Object unWrappedO = WrappedO.ToObject(); * Map map2 = (Map)unWrappedO; * Assert.True(((int)map.get("int")) == i); * Assert.True(((long)map.get("long")) == lng); * Assert.True(((DateTime)map.get("date")).Equals(date));*/ }
/* * public static Tuple<object, Type> ToObject(this NSObject nsO) => nsO.ToObject(null); * * public static Tuple<object, Type> ToObject(this NSObject nsO, Type type) * */ public static object ToObject(this NSObject nsO) => nsO.ToObject(null);
public static object ToObject(this NSObject nsO) { return(nsO.ToObject(null)); }
public static Tuple <object, Type> ToObject(this NSObject nsO) { return(nsO.ToObject(null)); }