HI Kris,

Well if you have a confirmed bug please report it at bugzilla.

Anyway, I wouldn't use a try-fail-backtrack-try_diferently process to
approach this coding problem. 

I would use the method FindMembers:

        Button b = new Button ("I am a button");
        MemberInfo[] arrayMemberInfo = b.GetType().FindMembers(MemberTypes.Method | 
MemberTypes.Property,
                BindingFlags.Public | BindingFlags.Instance,
                Type.FilterName,
                "ModifyBg");
        if (arrayMemberInfo == null || arrayMemberInfo.Length == 0)
                // throw some error here, about not having the appropriate member
        if (arrayMemberInfo.Length > 1)
                // throw some error here, about having overloads 
                // or look for the one with appropriate parameters
        if (arrayMemberInfo[0] is PropertyInfo) {
                PropertyInfo pInfo = arrayMemberInfo[0] as PropertyInfo;
                System.Object[] args= new System.Object[2];
                args[0] = StateType.Normal;
                args[1] = new Gdk.Color(255,0,0);
                pInfo.SetValue(b, args, null);
        } else {
                // do as a method here
        }

Hope it helps,

-- 
Rafael "Monoman" Teixeira 
Mono Hacker since 16 Jul 2001 - http://www.go-mono.org/
Mono Brasil Founding Member - http://monobrasil.redesolbrasil.org/
English Blog: http://monoblog.blogspot.com/
Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/

On Wed, 2004-03-17 at 19:43, Kris Luyten wrote:
> Hi,
> 
> I am implementing a library that relies heavily on reflection (a User
> Interface Markup Language renderer). It dynamically sets properties of
> widgets. Since the library does not know whether it is dealing with a
> method or a property it tries to load the specified string (e.g.
> "ModifyBg") as a property first, and when this fails it tries to load it
> as a method.
> 
> Since a couple of weeks, the following code hangs, instead of throwing
> an exception or just failing:
> 
>       Button b = new Button ("I am a button");
>       PropertyInfo pInfo = b.GetType().GetProperty("ModifyBg");
>       System.Object[] args= new System.Object[2];
>       args[0] = StateType.Normal;
>       args[1] = new Gdk.Color(255,0,0);
>       pInfo.SetValue(b, args, null);
> 
> The second line of the code succeeds, although ModifyBg is a method
> afaik. Still, the program hangs on the last line. If someone wants to
> test the full example, it is available here:
> http://research.edm.luc.ac.be/~kris/projects/uiml.net/examples/test16.cs
> 
> I am not sure whether this behavior is caused by a bug in mono or gtk#,
> or a mistake I made.
> 
> my specs:
> Debian Sid
> Mono JIT compiler version 0.30.99.20040307
> Mono C# compiler version 0.30.99.51827
> Gtk# from CVS, two weeks old
> 
> 
> Regards,
> Kris

_______________________________________________
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to