Caliburn-Micro / Caliburn.Micro

A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
http://caliburnmicro.com/
MIT License
2.8k stars 779 forks source link

Error when navigation with decimal parameters and custom culture is set #72

Closed matopeto closed 10 years ago

matopeto commented 10 years ago

Hi

i discovered error, when I navigation to secondViewModel and fill decimal parameter and custom culture for whole application

I set in bootstraper

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("sk-Sk");

Than I call:

 _nav.UriFor<SecondViewModel>().WithParam(s => s.Dec, (Decimal)1.1).Navigate();

And on second view model I get 11 as value of Dec, (instead of 1.1).

Problem is that 1.1 is serialized with culture info to "1,1", but it is deserialize without correct cultured info to 11.

Minimal project to reproduce error is here: https://dl.dropboxusercontent.com/u/81893/CaliburnDecimalBug.zip

Is there any workaround?

belyansky commented 10 years ago

Some time ago I faced the same problem. To fix this issue I've added additional custom converter:

MessageBinder.CustomConverters.Add(
    typeof(decimal), (value, context) =>
        {
            decimal result;
            decimal.TryParse(value.ToString(), out result);
            return result;
        });
belyansky commented 10 years ago

I think that such decimal converter can be added by default in the dictionary of custom converters inside of the framework (as it's done for DateTime converter).

matopeto commented 10 years ago

Thanks, it is working workaround.

I will leave this issue open, I don't know if it is a bug (the error is also if type is double or float). If the author of caliburn decides that is not a bug, they can close the issue.

nigel-sampson commented 10 years ago

It definitely looks like a bug, will close this when it's been fixed.

tibel commented 10 years ago

The issue does not happen when using CM 2.0, only when using 1.5.2

matopeto commented 10 years ago

yes, I am using version 1.5.2, it is invalid because 1.5.2 is unsupported?

tibel commented 10 years ago

Because 2.0 is the update for 1.5.2.