~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/maccore/src/Foundation/NSArray.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// Copyright 2009-2010, Novell, Inc.
 
3
// Copyright 2011, 2012 Xamarin Inc
3
4
//
4
5
// Permission is hereby granted, free of charge, to any person obtaining
5
6
// a copy of this software and associated documentation files (the
48
49
                        return FromNSObjects (_items);
49
50
                }
50
51
 
 
52
                static public NSArray FromNSObjects (int count, params NSObject [] items)
 
53
                {
 
54
                        if (items.Length < count)
 
55
                                throw new ArgumentException ("count is larger than the number of items", "count");
 
56
                        
 
57
                        IList<NSObject> _items = items;
 
58
                        return FromNSObjects (_items, count);
 
59
                }
 
60
 
51
61
                public static NSArray FromObjects (params object [] items)
52
62
                {
53
63
                        if (items == null)
56
66
                        for (int i = 0; i < items.Length; i++){
57
67
                                var k = NSObject.FromObject (items [i]);
58
68
                                if (k == null)
59
 
                                        throw new Exception (String.Format ("Do not know how to marshal object of type {0} to an NSObject", k.GetType ()));
 
69
                                        throw new ArgumentException (String.Format ("Do not know how to marshal object of type '{0}' to an NSObject", items [i].GetType ()));
60
70
                                nsoa [i] = k;
61
71
                        }
62
72
                        return FromNSObjects (nsoa);
75
85
                        return arr;
76
86
                }
77
87
 
 
88
                internal static NSArray FromNSObjects (IList<NSObject> items, int count)
 
89
                {
 
90
                        if (items == null)
 
91
                                return new NSArray (true);
 
92
                        
 
93
                        IntPtr buf = Marshal.AllocHGlobal (items.Count * IntPtr.Size);
 
94
                        for (int i = 0; i < count; i++)
 
95
                                Marshal.WriteIntPtr (buf, i * IntPtr.Size, items [i].Handle);
 
96
                        NSArray arr = NSArray.FromObjects (buf, count);
 
97
                        Marshal.FreeHGlobal (buf);
 
98
                        return arr;
 
99
                }
 
100
 
78
101
                static public NSArray FromStrings (params string [] items)
79
102
                {
80
103
                        if (items == null)
123
146
                {
124
147
                        if (handle == IntPtr.Zero)
125
148
                                return null;
126
 
                        
127
 
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCount);
 
149
 
 
150
#if MONOMAC
 
151
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCountHandle);
 
152
#else
 
153
                        uint c = Messaging.UInt32_objc_msgSend (handle, Selector.GetHandle (selCount));
 
154
#endif
128
155
                        string [] ret = new string [c];
129
156
 
130
157
                        for (uint i = 0; i < c; i++){
131
 
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_, i);
 
158
#if MONOMAC
 
159
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_Handle, i);
 
160
#else
 
161
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, Selector.GetHandle (selObjectAtIndex_), i);
 
162
#endif
132
163
                                ret [i] = NSString.FromHandle (p);
133
164
                        }
134
165
                        return ret;
139
170
                {
140
171
                        if (handle == IntPtr.Zero)
141
172
                                return null;
142
 
                        
143
 
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCount);
 
173
 
 
174
#if MONOMAC
 
175
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCountHandle);
 
176
#else
 
177
                        uint c = Messaging.UInt32_objc_msgSend (handle, Selector.GetHandle (selCount));
 
178
#endif
144
179
                        T [] ret = new T [c];
145
180
 
146
181
                        for (uint i = 0; i < c; i++){
147
 
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_, i);
 
182
#if MONOMAC
 
183
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_Handle, i);
 
184
#else
 
185
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, Selector.GetHandle (selObjectAtIndex_), i);
 
186
#endif
148
187
 
149
188
                                ret [i] = (T) Runtime.GetNSObject (p);
150
189
                                ret [i].Handle = p;
173
212
                {
174
213
                        if (handle == IntPtr.Zero)
175
214
                                return null;
176
 
                        
177
 
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCount);
 
215
 
 
216
#if MONOMAC
 
217
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCountHandle);
 
218
#else
 
219
                        uint c = Messaging.UInt32_objc_msgSend (handle, Selector.GetHandle (selCount));
 
220
#endif
178
221
                        T [] ret = new T [c];
179
222
 
180
223
                        for (uint i = 0; i < c; i++){
181
 
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_, i);
 
224
#if MONOMAC
 
225
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_Handle, i);
 
226
#else
 
227
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, Selector.GetHandle (selObjectAtIndex_), i);
 
228
#endif
182
229
 
183
230
                                ret [i] = createObject (p);
184
231
                        }
189
236
                {
190
237
                        if (handle == IntPtr.Zero)
191
238
                                return null;
192
 
                        
193
 
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCount);
 
239
 
 
240
#if MONOMAC
 
241
                        uint c = Messaging.UInt32_objc_msgSend (handle, selCountHandle);
 
242
#else
 
243
                        uint c = Messaging.UInt32_objc_msgSend (handle, Selector.GetHandle (selCount));
 
244
#endif
194
245
                        T [] ret = new T [c];
195
246
 
196
247
                        for (uint i = 0; i < c; i++){
197
 
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_, i);
 
248
#if MONOMAC
 
249
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, selObjectAtIndex_Handle, i);
 
250
                                #else
 
251
                                IntPtr p = Messaging.IntPtr_objc_msgSend_UInt32 (handle, Selector.GetHandle (selObjectAtIndex_), i);
 
252
#endif
198
253
 
199
254
                                ret [i] = creator (p);
200
255
                        }