[Mono-bugs] [Bug 471359] Binder: ChangeType should only be invoked for non-default binder

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Dec 7 08:49:13 EST 2010


https://bugzilla.novell.com/show_bug.cgi?id=471359

https://bugzilla.novell.com/show_bug.cgi?id=471359#c3


Joe Mistachkin <joe at mistachkin.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joe at mistachkin.com

--- Comment #3 from Joe Mistachkin <joe at mistachkin.com> 2010-12-07 13:49:11 UTC ---
I just ran into this bug as well.  Here is another simple example:

using System;
using System.Globalization;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        private class CustomBinder : Binder
        {
            public override object ChangeType(
                object value,
                Type type,
                CultureInfo culture
                )
            {
                Console.WriteLine(
                    "ChangeType INVOKED: value = {0}, valueType = {1}, " +
                    "type = {2}", value, (value != null) ?
                        value.GetType() : null, type);

                return Type.DefaultBinder.ChangeType(value, type, culture);
            }

            ///////////////////////////////////////////////////////////////////

            public override FieldInfo BindToField(
                BindingFlags bindingAttr,
                FieldInfo[] match,
                object value,
                CultureInfo culture
                )
            {
                throw new NotImplementedException();
            }

            ///////////////////////////////////////////////////////////////////

            public override MethodBase BindToMethod(
                BindingFlags bindingAttr,
                MethodBase[] match,
                ref object[] args,
                ParameterModifier[] modifiers,
                CultureInfo culture,
                string[] names,
                out object state
                )
            {
                throw new NotImplementedException();
            }

            ///////////////////////////////////////////////////////////////////

            public override void ReorderArgumentArray(
                ref object[] args,
                object state
                )
            {
                throw new NotImplementedException();
            }

            ///////////////////////////////////////////////////////////////////

            public override MethodBase SelectMethod(
                BindingFlags bindingAttr,
                MethodBase[] match,
                Type[] types,
                ParameterModifier[] modifiers
                )
            {
                throw new NotImplementedException();
            }

            ///////////////////////////////////////////////////////////////////

            public override PropertyInfo SelectProperty(
                BindingFlags bindingAttr,
                PropertyInfo[] match,
                Type returnType,
                Type[] indexes,
                ParameterModifier[] modifiers
                )
            {
                throw new NotImplementedException();
            }
        }

        ///////////////////////////////////////////////////////////////////////

        public void TestMethod(string value)
        {
            Console.WriteLine(value);
        }

        ///////////////////////////////////////////////////////////////////////

        static void Main(string[] args)
        {
            Binder binder = new CustomBinder();
            Program program = new Program();

            MethodInfo methodInfo = typeof(Program).GetMethod("TestMethod");

            methodInfo.Invoke(
                program, BindingFlags.Default, binder,
                new object[] { "foobar" }, null);

            Console.WriteLine("done");
            Console.ReadKey();
        }
    }
}

Expected results:

foobar
done

Actual results:

ChangeType INVOKED: value = foobar, valueType = System.String, type =
System.String
foobar
done

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list