[Mono-dev] parametric types and nested classes

Robert Sim robert.sim at gmail.com
Wed Apr 2 16:57:28 EDT 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080402/5fab7af4/attachment.html 


More information about the Mono-devel-list mailing list