Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinRT Replacement for System.ComponentModel.TypeConverter

It doesn't look like TypeConverter is available to use. What is recommended to replace this?

I was going to go and create my own TypeConverter class to use to replace it, but if there is a new or better way in WinRT to do it, I'd go that route. There are also many other classes that I would need to recreate; like all the default type converters.

like image 802
Josh Close Avatar asked Nov 04 '22 15:11

Josh Close


1 Answers

There is no TypeConverter class in the WinRT and the team has not announced any plans to include it in a future release. You have a number of options.

Option 1: If the conversion is to be done as part of a data binding use the IValueConverter interface as Dennis mentioned.

Option 2: If you are the creator of the type you can add your own explicit or implicit operators to support casting:

http://msdn.microsoft.com/en-US/library/xhbhezf4(v=vs.80).aspx

http://msdn.microsoft.com/en-US/library/z5z9kes2(v=vs.80).aspx

Option 3: You could create your own TypeConverter class.

Option 4: (The way I'd do it if not part of a binding) You can add your own extension methods:

static public class ConverterExtensions
{
    static public string ToFixedString(this double value)
    {
        return value.ToString("D");
    }
}

Which would let you write code like this:

double d = 123.45;
string str = d.ToFixedString(); // str now equals "123"
like image 127
Jared Bienz - MSFT Avatar answered Nov 15 '22 04:11

Jared Bienz - MSFT