You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
committed by
Jo Shields
parent
183bba2c9a
commit
6992685b86
@@ -32,7 +32,7 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if MONOTOUCH
|
||||
#if MONOTOUCH || XAMMAC
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -43,14 +43,39 @@ using System.Runtime.InteropServices;
|
||||
namespace System {
|
||||
|
||||
public partial class TimeZoneInfo {
|
||||
|
||||
static TimeZoneInfo CreateLocal ()
|
||||
{
|
||||
using (Stream stream = GetMonoTouchData (null)) {
|
||||
return BuildFromStream ("Local", stream);
|
||||
}
|
||||
}
|
||||
|
||||
static TimeZoneInfo FindSystemTimeZoneByIdCore (string id)
|
||||
{
|
||||
using (Stream stream = GetMonoTouchData (id)) {
|
||||
return BuildFromStream (id, stream);
|
||||
}
|
||||
}
|
||||
|
||||
static void GetSystemTimeZones (List<TimeZoneInfo> systemTimeZones)
|
||||
{
|
||||
foreach (string name in GetMonoTouchNames ()) {
|
||||
using (Stream stream = GetMonoTouchData (name, false)) {
|
||||
if (stream == null)
|
||||
continue;
|
||||
systemTimeZones.Add (BuildFromStream (name, stream));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport ("__Internal")]
|
||||
extern static IntPtr monotouch_timezone_get_names (ref int count);
|
||||
extern static IntPtr xamarin_timezone_get_names (ref int count);
|
||||
|
||||
static ReadOnlyCollection<string> GetMonoTouchNames ()
|
||||
{
|
||||
int count = 0;
|
||||
IntPtr array = monotouch_timezone_get_names (ref count);
|
||||
IntPtr array = xamarin_timezone_get_names (ref count);
|
||||
string [] names = new string [count];
|
||||
for (int i = 0, offset = 0; i < count; i++, offset += IntPtr.Size) {
|
||||
IntPtr p = Marshal.ReadIntPtr (array, offset);
|
||||
@@ -62,24 +87,20 @@ namespace System {
|
||||
}
|
||||
|
||||
[DllImport ("__Internal")]
|
||||
extern static IntPtr monotouch_timezone_get_data (string name, ref int size);
|
||||
extern static IntPtr xamarin_timezone_get_data (string name, ref int size);
|
||||
|
||||
static Stream GetMonoTouchData (string name, bool throw_on_error = true)
|
||||
{
|
||||
int size = 0;
|
||||
IntPtr data = monotouch_timezone_get_data (name, ref size);
|
||||
IntPtr data = xamarin_timezone_get_data (name, ref size);
|
||||
if (size <= 0) {
|
||||
if (throw_on_error)
|
||||
throw new TimeZoneNotFoundException ();
|
||||
throw new TimeZoneNotFoundException (name);
|
||||
return null;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
var s = new UnmanagedMemoryStream ((byte*) data, size);
|
||||
s.Closed += delegate {
|
||||
Marshal.FreeHGlobal (data);
|
||||
};
|
||||
return s;
|
||||
return new HGlobalUnmanagedMemoryStream ((byte*) data, size, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user