[Mono-dev] Patch to Fix CanConvertTo and ConverTo of/for primitive types.

Alexandre Miguel Pedro Gomes alexmipego at gmail.com
Fri Jan 15 15:28:56 EST 2010


Hi,

I've detected a problem with type convertion when using the TypeConverters
for a type. My initial test case for comparing Mono 2.4.* and trunk results
with the .Net framework was as such:

-- code --
using System;
using System.ComponentModel;

namespace PrimitiveTests
{
    class Program
    {
        static void Main(string[] args)
        {
            Type[] types = { typeof(Boolean),
                               typeof(Byte),
                               typeof(SByte),
                               typeof(Int16),
                               typeof(UInt16),
                               typeof(Int32),
                               typeof(UInt32),
                               typeof(Int64),
                               typeof(UInt64),
                               typeof(IntPtr),
                               typeof(UIntPtr),
                               typeof(Char),
                               typeof(Double),
                               typeof(Single)};

            foreach(Type type in types)
                Console.WriteLine("CanConvert " + type + " to Int32? " +
TypeDescriptor.GetConverter(type).CanConvertTo(typeof(Int32)));


Console.WriteLine(TypeDescriptor.GetConverter(typeof(uint)).ConvertTo((uint)134,
typeof(int)));

            Console.ReadKey();
        }
    }
}
-- code --

This revealed that all primitives with a few exceptions (bool, intptr, char)
should be allowed to be converted and Mono's CanConvertTo (and the actual
conversion) was failing. I've created a patch and necessary unit tests to
fix the issue and tested both with the previous script and with my (now
patched) Mono 2.4.3 server's install.

If someone could review, it would be appreciated. I can commit if the
maintainer approves the code.

Regards,

-- 
Alexandre Gomes
http://www.alexandre-gomes.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100115/f06fec10/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ConvertTo.patch
Type: text/x-diff
Size: 7990 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100115/f06fec10/attachment-0001.bin 


More information about the Mono-devel-list mailing list