Re: Extending System.Drawing.Rectangle...

Gyorgy Bozoki <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <000001c78188$89b27da0$9cfcbb4c@homepc>
Guys,

Thanks for the replies - my question was mostly theoretical, just out of
curiosity. I suspected that there is no way to tack on a bunch of methods to
a struct. I already implemented a new struct which has all the Rectangle
functionality and all the new methods that I wanted to add - I find the
Rectangle class very limited, so I wanted a bunch of extra methods (no more
internal fields.) This way at least there is no delegation cost (there is no
internal Rectangle instance to call) - the conversion cost will be less
during run-time.

It's quite a shame that there is no way to extend structures in .Net - this
is not the first time I run into this and I don't like my solution because
all those other functions that accept a Rectangle will not accept my
RectangleX class - I'll frequently have to do conversions. I also thought
about using a static helper class (also suggested by Simon) - technically
it's fine but it has similar shortcomings - it needs extra code that causes
clutter. <grrr>

I was hoping that someone came up with some sneaky workaround for the struct
limitation. :)

Thanks again,
Gyorgy Bozoki

> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to
> build apps and controls
> [mailto:[email protected]] On Behalf Of
> Chris Anderson
> Sent: Wednesday, April 18, 2007 01:28
> To: [email protected]
> Subject: Re: [DOTNET-WINFORMS] Extending System.Drawing.Rectangle...
>
> You'd probably need to wrap the Rectangle inside a new class
> and internally use the Rectangle to perform standard
> Rectangle functionality, tgen add what you want.
> Of course you wouldn't be able to use the new class *as* a
> Rectangle where a Rectangle was expected.
>
> In .net 3.0 you *might* be able to use extension methods. (
> not 100% sure if you can use them on structs, but worth checking)
>
> What extra functionality are you looking to add?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.