Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

c# - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...