views:

248

answers:

4

We use DevExpress and with today release came a weird change to one of their printing class.

The class is named ClosedShapeBase and it is used to print out shape in a report.

The class itself is public, but some of its properties are protected internal abstract, like

public abstract class ClosedShapeBase : ShapeBase
{
    protected internal abstract PointF[] CreatePoints(RectangleF bounds, int angle);
}

Is there is any cryptic way to be able to override that member even if it is internal?

+1  A: 
public class MyShape : ClosedShapeBase
{
    protected internal override PointF[] CreatePoints(RectangleF bounds, int angle)
    {
        ...
    }
}

You just have to respect the "protected internal" qualifier in the overridden class.

Filip Navara
I am not inheriting form the same assembly. In that case, the error is "no suitable method found to override".
Pierre-Alain Vigeant
But what is it good for? Why do DevExpress use this qualifier?
HuBeZa
They do this so that their painters and information classes can access those. DevEx uses at least 4 or 5 classes to get most things done.
Thomas G. Mayfield
They seem to have changed they class implementation form 9.1 to 9.2. I have reported to DevExpress about that, but I wanted to check if there was another way of overriding that.
Pierre-Alain Vigeant
There is. See my answer below from earlier. Override it as if that "internal" doesn't exist, as that qualifier only has effects inside of DevEx's own project.
Thomas G. Mayfield
I check this code and it won't compile. You can override it using "protected override" modifiers only
HuBeZa
+3  A: 

The "protected internal" just means that DevExpress's own code in their project can access it. For all purposes outside of that project (except for some magic in AssemblyInfo), it's the same as if it was only "protected". DevEx does that all over the place.

You don't need to maintain the "internal" in your own override:

public class Foo
    : ClosedShapeBase
{
    protected override ShapeBase CloneShape()
    {
        throw new NotImplementedException();
    }

    protected override PointF[] CreatePoints(RectangleF bounds, int angle)
    {
        throw new NotImplementedException();
    }

    protected override ILinesAdjuster GetLinesAdjuster()
    {
        throw new NotImplementedException();
    }
}
Thomas G. Mayfield
Interesting, I didn't know that. I was able to create a test shape like your example, but I also have an error about an internal property getter. I used reflector to check that property and the definition is "internal abstract PreviewStringId ShapeStringId { get; }". Got any idea?
Pierre-Alain Vigeant
I was able to use your comment to figure out something else. I inherited from another child class of ClosedShapeBase that was already overriding that private internal property. Thank you.
Pierre-Alain Vigeant
A: 

protected internal means that any subclass can access (in your case override) the member. The subclass can be located in any assembly. All classes of the assembly in which your baseclass is defined can also access the member.

Best Regards

Oliver Hanappi
+2  A: 

protected internal does not mean protected and internal. It means protected OR internal. So you should be able to override that method in other places outside of the assembly where that ClosedShapeBase is defined.

Mehmet Aras
To be more specific, if you override the class in the same assembly it will also contain the 'internal' modifier. In this case the method is abstract so you cannot "use" it, but if it was virtual - you could use it either by inheriting to class or by creating an instance of it in the same assembly.
HuBeZa
What exactly do you mean by 'you cannot "use" it? The bottom line is you CAN overrride that method with protected internal access modifier both in the same assembly or in another assembly.
Mehmet Aras