Skip to content

Commit

Permalink
Avoid using reflection to initialize RegionInfo from iOS current NSLo…
Browse files Browse the repository at this point in the history
…cale
  • Loading branch information
spouliot committed Apr 27, 2013
1 parent 56d7272 commit b46553c
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions mcs/class/corlib/System.Globalization/RegionInfo.MonoTouch.cs
Expand Up @@ -5,7 +5,7 @@
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2012 Xamarin Inc.
// Copyright 2012-2013 Xamarin Inc.
//
// The class can be either constructed from a string (from user code)
// or from a handle (from iphone-sharp.dll internal calls). This
Expand Down Expand Up @@ -35,34 +35,18 @@
#if MONOTOUCH

using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace System.Globalization {

public partial class RegionInfo {

static Type nslocale;

static Type NSLocale {
get {
if (nslocale == null)
nslocale = Type.GetType ("MonoTouch.Foundation.NSLocale, monotouch, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
return nslocale;
}
}


[DllImport ("__Internal")]
extern static string monotouch_get_locale_country_code ();

static RegionInfo CreateFromNSLocale ()
{
try {
var cl = NSLocale.GetProperty ("CurrentLocale", BindingFlags.Static | BindingFlags.Public).GetGetMethod ();
var cc = NSLocale.GetProperty ("CountryCode", BindingFlags.Instance | BindingFlags.Public).GetGetMethod ();

object current = cl.Invoke (null, null);
return new RegionInfo ((string) cc.Invoke (current, null));
}
catch (TargetInvocationException tie) {
throw tie.InnerException;
}
return new RegionInfo (monotouch_get_locale_country_code ());
}
}
}
Expand Down

0 comments on commit b46553c

Please sign in to comment.