overriding property with different type

  • Thread starter Doychin Bondzhev
  • Start date
D

Doychin Bondzhev

Is it posible to override a property in descendant class with different
type?

here is a simple example of what I'm trying to do:


using System;
using System.Windows.Forms;

namespace ClassLibrary1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class TestControl: Control
{
private String m_Visble;
public TestControl()
{
//
// TODO: Add constructor logic here
//
m_Visble = "Yes";
}
public new String Visible
{
get
{
return m_Visble;
}
set
{
m_Visble = value;
}
}
}
}

After building this code I can add ths control to the toolbox and also I can place it on the form but Property grid does not work properly with it.

Is this a bug in Property grid or there is somthing that I miss here?

also if this is not the right group for such question where should I post it?

thanks in advance.
 
J

Jon Skeet

Doychin Bondzhev said:
Is it posible to override a property in descendant class with different
type?

Nope - if you think about it, that would break the Liskov
Substitutability Principle (basically, you should be able to use a
subclass the way you use the superclass). This *may* arrive with
generics to some extent, however - I'm not sure.

After building this code I can add ths control to the toolbox and also
I can place it on the form but Property grid does not work properly with it.

Is this a bug in Property grid or there is somthing that I miss here?

The property grid isn't going to be looking at your Visible property,
but rather the "normal" one (I suspect).
 

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