[Mono-dev] Invoking method from base class in embedded environment

Janne Rantala janne.rantala at gmail.com
Mon Aug 28 10:50:28 EDT 2006


Hi,

I have two classes, simply Class1 and Class2. Class1 has only one
method, public string get(). Class2 extends Class1.

Now when I create an instance of Class1 in embedded environment, and
wish to invoke that get() -method, either function
mono_class_get_method_from_name cannot find it and function
mono_class_get_methods iterates only methods available in Class2
(which in this case is .ctor).

Function mono_class_get_parent() does give me Class1, and I can see
that it has that get -method but getting that method from Class1 and
trying to invoke it with Class2 doesn't work either.

Here's the code:

using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
    public class Class2 : Class1
    {
        public Class2()
            : base()
        {

        }
    }

    public class Class1
    {
        public Class1()
        {
            Console.WriteLine("Parent constructor");
        }

        public string get()
        {
            return "Hello from parent class";
        }
    }
}

Before get method is invoked I print all methods from Class2, and this
is what is printed:

Parent constructor
methods: .ctor

As it can be seen, constructor from parent class is invoked when
object is created, but only method .ctor from Class2 is found. I'd
suppose that method get should be visible as well?

And also if program is ran from command line it works fine.

Can anyone confirm this kind of behaviour or I'm I doing something wrong?

Janne



More information about the Mono-devel-list mailing list