how to derive class from generic Image class

M

Marcin Kowalewski

Hi I've got a stupid problem with code below :

using System;
using System.Drawing;
....
public class CsrcImage :Image
{
public CsrcImage()
{
//
}
}
....

Compiler return error:
'System.Drawing.Image.Image()' is inaccessible due to its protection level

OK I know that Image is an Abstract class with no constructor, but it must
be magic trick to derive new class from Image.
For example Bitmap class is derived from Image (but is sealed unfortunately)

Please help me
Marcin
 
J

Jay B. Harlow [MVP - Outlook]

Marcin,
OK I know that Image is an Abstract class with no constructor, but it must
be magic trick to derive new class from Image.
Actually the constructor of Image is declared as internal, which means that
Bitmap which is defined in the same assembly (System.Drawing) as Image is
able to derive from it.

CsrcImage which is defined outside of the System.Drawing assembly cannot
access the internal constructor of Image, hence it cannot derive from it.

Its a somewhat clever OO trick to allow an object model in an assembly that
others cannot participate in.

Hope this helps
Jay
 
M

Marcin Kowalewski

Thanks Jay,

does it mean that there is NO WAY to derive my class from Image??

Marcin
 
P

Peter Rilling

It also indicates to me that they did not think their design of the Image
class through very well. If they had truly generalized the Image class,
then they would not fear others who wanted to develop their own image
format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top