Overriding inherited interface members

  • Thread starter Thread starter Joshua Frank
  • Start date Start date
J

Joshua Frank

Hi All,

Is it possible to do this? I have a class that inherits from DataGrid,
which implements ISupportInitialize. I'd like my class to implement
this too, but you can't implement an interface that your base class
already implements. I can't find any combination of keywords to support
this. And yet, it seems an obvious requirement. Sometime you really
need to be able to override implementation inherited members. Is there
a way to do this?

Cheers,
Josh
 
The DataSet declares the BeginInit() and EndInit() functions as virtual, so
all you need to do in your derived class is to override them, e.g.

class MyDataSet : DataSet
{
public override void BeginInit()
{
base.BeginInit();
// Your code
}

public override void EndInit()
{
// Your code
base.EndInit();
}
}

Ken
 
Hi Joshua,

Is this what you mean?

public class C : DataGrid, ISupportInitialize
{
public new void BeginInit()
{
}

public new void EndInit()
{
}
}

I get no compiler errors here. No runtime errors either, though I haven't tested with anything inside Begin/EndInit.
 
Morten said:
Hi Joshua,

Is this what you mean?

public class C : DataGrid, ISupportInitialize
{
public new void BeginInit()
{
}

public new void EndInit()
{
}
}

I get no compiler errors here. No runtime errors either, though I
haven't tested with anything inside Begin/EndInit.
Yes, although this doesn't work in VB (translated appropriately), which
is what I'm using. I wonder why the difference, since it's a core
framework issue.
 
Morten said:
Hi Joshua,

Is this what you mean?

public class C : DataGrid, ISupportInitialize
{
public new void BeginInit()
{
}

public new void EndInit()
{
}
}

I get no compiler errors here. No runtime errors either, though I
haven't tested with anything inside Begin/EndInit.
Yes, although this doesn't work in VB (translated appropriately), which
is what I'm using. I wonder why the difference, since it's a core
framework issue.
 
Morten said:
Hi Joshua,

Is this what you mean?

public class C : DataGrid, ISupportInitialize
{
public new void BeginInit()
{
}

public new void EndInit()
{
}
}

I get no compiler errors here. No runtime errors either, though I
haven't tested with anything inside Begin/EndInit.
Yes, although this doesn't work in VB (translated appropriately), which
is what I'm using. I wonder why the difference, since it's a core
framework issue.
 
In VB, I get the following error:

'Public Overrides Sub BeginInit()' cannot override 'Public Overridable
NotOverridable Sub BeginInit()' because it is declared 'NotOverridable'.

From this and the other reply, it seems like C# has this capability and
VB doesn't, and yet it's a pretty basic need, and one that should be
squarely in the CLR and have nothing to do with language choice. So now
I'm annoyed. Does anyone know how to accomplish this in VB?
 
Back
Top