Skip to content

Commit 8d99527

Browse files
authored
Merge pull request #308 from TobiasPott/develop
Use invariant device locale for number format conversion
2 parents d0577f4 + 36ef6b0 commit 8d99527

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

Parse.Test/ConversionTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,22 @@ struct DummyValueTypeB { }
1818

1919
[TestMethod]
2020
public void TestToWithConstructedNullableNonPrimitive() => Assert.ThrowsException<InvalidCastException>(() => Conversion.To<DummyValueTypeA?>(new DummyValueTypeB { }));
21+
22+
23+
24+
[TestMethod]
25+
public void TestConvertToFloatUsingNonInvariantNumberFormat()
26+
{
27+
try
28+
{
29+
float inputValue = 1234.56f;
30+
string jsonEncoded = Common.Internal.Json.Encode(inputValue);
31+
float convertedValue = (float) Conversion.ConvertTo<float>(jsonEncoded);
32+
Assert.IsTrue(inputValue == convertedValue);
33+
}
34+
catch (Exception ex)
35+
{ throw ex; }
36+
}
37+
2138
}
2239
}

Parse/Internal/ParseCorePlugins.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
using Parse.Common.Internal;
88
using Parse.Core.Internal;
99

10+
#if DEBUG
11+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Parse.Test")]
12+
#endif
13+
1014
namespace Parse.Core.Internal
1115
{
1216
public class ParseCorePlugins : IParseCorePlugins

Parse/Public/ParseClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,19 @@ public string MasterKey
213213
/// <summary>
214214
/// Authenticates this client as belonging to your application. This must be
215215
/// called before your application can use the Parse library. The recommended
216-
/// way is to put a call to <c>ParseFramework.Initialize</c> in your
216+
/// way is to put a call to <c>ParseClient.Initialize</c> in your
217217
/// Application startup.
218218
/// </summary>
219219
/// <param name="identifier">The Application ID provided in the Parse dashboard.
220220
/// </param>
221-
/// <param name="key">The .NET API Key provided in the Parse dashboard.
221+
/// <param name="serverURI">The server URI provided in the Parse dashboard.
222222
/// </param>
223-
public static void Initialize(string identifier, string key) => Initialize(new Configuration { ApplicationID = identifier, Key = key });
223+
public static void Initialize(string identifier, string serverURI) => Initialize(new Configuration { ApplicationID = identifier, ServerURI = serverURI });
224224

225225
/// <summary>
226226
/// Authenticates this client as belonging to your application. This must be
227227
/// called before your application can use the Parse library. The recommended
228-
/// way is to put a call to <c>ParseFramework.Initialize</c> in your
228+
/// way is to put a call to <c>ParseClient.Initialize</c> in your
229229
/// Application startup.
230230
/// </summary>
231231
/// <param name="configuration">The configuration to initialize Parse with.

Parse/Public/ParseObject.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,18 @@ internal virtual void SetDefaultValues() { }
218218
/// <typeparam name="T">The ParseObject subclass type to register.</typeparam>
219219
public static void RegisterSubclass<T>() where T : ParseObject, new() => SubclassingController.RegisterSubclass(typeof(T));
220220

221+
/// <summary>
222+
/// Registers a custom subclass type with the Parse SDK, enabling strong-typing of those ParseObjects whenever
223+
/// they appear. Subclasses must specify the ParseClassName attribute, have a default constructor, and properties
224+
/// backed by ParseObject fields should have ParseFieldName attributes supplied.
225+
/// </summary>
226+
/// <param name="type">The ParseObject subclass type to register.</param>
227+
public static void RegisterSubclass(Type type) { if (typeof(ParseObject).IsAssignableFrom(type)) SubclassingController.RegisterSubclass(type); }
228+
221229
internal static void UnregisterSubclass<T>() where T : ParseObject, new() => SubclassingController.UnregisterSubclass(typeof(T));
230+
internal static void UnregisterSubclass(Type type) { if (typeof(ParseObject).IsAssignableFrom(type)) SubclassingController.UnregisterSubclass(type); }
231+
232+
222233

223234
/// <summary>
224235
/// Clears any changes to this object made since the last call to <see cref="SaveAsync()"/>.

Parse/Public/Utilities/Conversion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static object ConvertTo<T>(object value)
5454

5555
if (ReflectionHelpers.IsPrimitive(typeof(T)))
5656
{
57-
return (T) Convert.ChangeType(value, typeof(T));
57+
return (T) Convert.ChangeType(value, typeof(T), System.Globalization.CultureInfo.InvariantCulture);
5858
}
5959

6060
if (ReflectionHelpers.IsConstructedGenericType(typeof(T)))
@@ -65,7 +65,7 @@ internal static object ConvertTo<T>(object value)
6565
Type innerType = ReflectionHelpers.GetGenericTypeArguments(typeof(T))[0];
6666
if (ReflectionHelpers.IsPrimitive(innerType))
6767
{
68-
return (T) Convert.ChangeType(value, innerType);
68+
return (T) Convert.ChangeType(value, innerType, System.Globalization.CultureInfo.InvariantCulture);
6969
}
7070
}
7171
Type listType = GetInterfaceType(value.GetType(), typeof(IList<>));

0 commit comments

Comments
 (0)