Re: Extending System.Drawing.Rectangle...

Fabian Schmied <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
Gyorgy,

> 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.

I don't believe delegating would cause any additional cost. Any calls
to the inner Rectangle instance could be inlined by the JIT compiler
(because Rectangle is a value type and thus sealed).

However, I agree that it is cumbersome that you can't simply attach
new operations to existing structures (or classes, actually) - that's
why I like extension methods in C# 3.0, they seem to be a clean way to
do this. (As long as you con't need to add state.) But that's only a
solution for the future, not for now.

Fabian
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.