I believe this is a known issue.  If I'm understanding you correctly,
when I first started developing with Mono, nested classes was one of the
things I was told couldn't be done.  There is a web page that explains
it, I just don't know where it's at for the moment.  Maybe someone else
knows?

________________________________

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Robert
Sim
Sent: Wednesday, April 02, 2008 3:57 PM
To: [email protected]
Subject: [Mono-dev] parametric types and nested classes


Hi, I'm having some casting problems with nested classes of classes
derived from parametric types. My peeks at the archives have failed to
turn anything up. The problem is described below.  It compiles and works
as expected in Visual Studio.  Compiling with gmcs gives me these
errors:

mono-gmcs: 1.2.4-6ubuntu6.1

Foo.cs(23,20): error CS0029: Cannot implicitly convert type `T' to
`BarHelper'
Foo.cs(24,10): error CS0029: Cannot implicitly convert type
`Foo<T>.NestedFoo.Property' to `BarHelper'
Foo.cs(25,13): error CS0030: Cannot convert type `Foo<T>.NestedFoo' to
`BarHelper'
Compilation failed: 3 error(s), 0 warnings

Foo.cs:
public class Foo<T> where T:new() {
    public class NestedFoo {
       
        T field=default(T);
       
        public T getField() { return field; }
       
        public T Property {
            get { return field; }
        }
        public static explicit operator T(NestedFoo foo) {
           return foo.field;
        }
    }
}

public class BarHelper {}

public class Bar : Foo<BarHelper> {
     public void  Test() {
         NestedFoo myFoo=new NestedFoo();
         // All three of these lines fail to compile, even if I insert
an explicit cast to BarHelper.
         BarHelper b=myFoo.getField();
         b=myFoo.Property;
         b=(BarHelper)myFoo;
     }
}

Thanks,
R

_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to