[Mono-dev] parametric types and nested classes

Gavin Landon Gavin.Landon at ignitetech.com
Wed Apr 2 17:30:02 EDT 2008

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


From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Robert
Sent: Wednesday, April 02, 2008 3:57 PM
To: mono-devel-list at lists.ximian.com
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

mono-gmcs: 1.2.4-6ubuntu6.1

Foo.cs(23,20): error CS0029: Cannot implicitly convert type `T' to
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
Compilation failed: 3 error(s), 0 warnings

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();


More information about the Mono-devel-list mailing list