[Mono-dev] parametric types and nested classes

Robert Sim robert.sim at gmail.com
Wed Apr 2 17:44:43 EDT 2008


Thanks.  Well, I've figured out it can be done if I try hard enough.
Explicitly declaring the type of myFoo does the trick:

 Foo<BarHelper>.NestedFoo myFoo=new Foo<BarHelper>.NestedFoo();


On Wed, Apr 2, 2008 at 2:30 PM, Gavin Landon <Gavin.Landon at ignitetech.com>
wrote:

> 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: mono-devel-list-bounces at lists.ximian.com
> [mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Robert
> Sim
> 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
> 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
>
>


-- 
Robert Sim
http://simra.net/blog
http://www.cs.ubc.ca/~simra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080402/913b5070/attachment-0001.html 


More information about the Mono-devel-list mailing list