[Mono-devel-list] Generics - Class Constraint

Stephen Quattlebaum stephen at covidimus.net
Sat Jul 30 00:47:00 EDT 2005

Trying to compile some C# code that uses generics on mono in Linux (gentoo).
I ran across the following problem (which is probably just unimplemented


       public static T QueryInterface<T>(object val)

            where T : class


            if (val == null)

                return null;


            // First, see if the given object can be directly cast

            // to the requested type.  This will be a common case,

            // especially when checking for standard behavior interface

            // implementations (like IXrcDataElement).

            T tval = val as T;

            if (tval != null)

                return tval;


            . more .



The error:


Xircle.Core/src/Core/XrcConvert.cs(118) error CS0077: The as operator should
be used with a reference type only (T is a value type)


Line #118 is the line that reads "T tval = val as T".  Looks like gmcs isn't
honoring the 'class' constraint (where T:class).  I found this bug in
bugzilla, which seems related:




The question:  Is that bug the same problem?  If so, I'll try compiling from
SVN again (got strange errors last time I tried), since the bug is marked
resolved.  If not, is there an ETA on when GMCS will honor 'class'


The gmcs I'm using is from the bitrock installer of mono



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050729/c4f263db/attachment.html 

More information about the Mono-devel-list mailing list