[Mono-list] Does GMCS support the default constructor constraint? (null ref excep.)

Ben Joldersma ben at joldersma.org
Thu Mar 23 11:04:24 EST 2006


So I sort of got past this problem, but one difference I noticed between
gmcs and .net 2.0's csc is that in ms if you explicity constrain a generic
definition with the new() constraint, the type constraint can be abstract /
otherwise not explicitly implement a public, parameterless constructor.

But in gmcs, you have to, which is a bit unfortunate, because I'd like to be
able to constrain my generic to a subset of types, but the base class of the
types needs to be abstract.  seems like a pretty typical scenario.

The other issue I noticed that is different involves type conversions.  Gmcs
complains that I cannot convert from type X to T, even if type X derives
from T.  I can cast it to an object, and then to a T -- so there is a
workaround, but i'd rather not.

Am I misusing generics?  I'm new to them, never used templates in C++ (at
least, never wrote any), so I'm not totally sure about the design principles
that apply here.

cheers,

--ben joldersma
http://ben.creationsnetwork.org

On 3/22/06, Julien Sobrier <julien at sobrier.net> wrote:
>
> Ben Joldersma wrote:
> > Hello all, I'm trying to compile my .net 2.0 application to mono
> > 1.1.13.4 <http://1.1.13.4>.  I'm getting the following error from nant
> > (I'm using the latest binary.)   My project builds corrrectly with .net
> > 2.0.  There are several places in my project were I require the new()
> > constraint.  Any suggestions would be much appreciated!
> >
> > --ben
>
> Hello,
> I was about to ask the same question: some of my classes have an implied
> constructor MyClass(), but it looks like I have to include this
> explicitly with gmcs, otherwise I get the error
> WARNING **: Missing method .ctor in assembly ... a run time
>
> I'll look deeper into this.
>
> Julien
>



--
--ben joldersma
http://ben.creationsnetwork.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20060323/8ddec5fa/attachment-0001.html


More information about the Mono-list mailing list