Hiding base class methods


G

Guest

I would like to find a way to completely hide selected methods of a base
class when inheriting from that base class. I know how to override a method
and replace a base class method using the "new" modifier on the method, but
then the method of the derived class shows up. I would like to be able to
completely hide a method so that it doesn't show up at all in an application
that instantiates the derived class. Any help would be appreciated.
 
Ad

Advertisements

T

Tim Wilson

If you compile the following code into an assembly, and then reference this
assembly in a project, then when you create an instance of the "Derived"
class, the method named "Method" will not show up in the editor through
intellisense. AFAIK, this is the only way to accomplish hiding inherited
members from an end-developer. Of course, if the end-developer specified
that the "Method" should be called against an instance of the "Derived"
class, although they will not get intellisense to complete the code, it will
compile since the method does exist. This is the reason why the
"NotSupportedException" is pitched.

using System;
using System.ComponentModel;

namespace MyNamespace
{
public class Base : System.Object
{
public void Method()
{
// Do something.
}
}

public class Derived : Base
{
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
public new void Method()
{
throw (new NotSupportedException("This method is not supported."));
}
}
}
 
G

Guest

OK, thanks - that does the trick!.

Tim Wilson said:
If you compile the following code into an assembly, and then reference this
assembly in a project, then when you create an instance of the "Derived"
class, the method named "Method" will not show up in the editor through
intellisense. AFAIK, this is the only way to accomplish hiding inherited
members from an end-developer. Of course, if the end-developer specified
that the "Method" should be called against an instance of the "Derived"
class, although they will not get intellisense to complete the code, it will
compile since the method does exist. This is the reason why the
"NotSupportedException" is pitched.

using System;
using System.ComponentModel;

namespace MyNamespace
{
public class Base : System.Object
{
public void Method()
{
// Do something.
}
}

public class Derived : Base
{
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
public new void Method()
{
throw (new NotSupportedException("This method is not supported."));
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

DanielF said:
I would like to find a way to completely hide selected methods of a base
class when inheriting from that base class. I know how to override a method
and replace a base class method using the "new" modifier on the method, but
then the method of the derived class shows up. I would like to be able to
completely hide a method so that it doesn't show up at all in an application
that instantiates the derived class. Any help would be appreciated.
 
G

Guest

Could you please help with a reverse problem. I have created a public class
with several public methods in it. I have derived a new class from the base
class. Intellisense does not "see" all the base class methods, though all
were made Public. I've even commented out many of the base class methods and
the derived class still shows theses methods. It seems that intellisense
isn't updating.

TIA, thanks is advance.

drumred

DanielF said:
OK, thanks - that does the trick!.

Tim Wilson said:
If you compile the following code into an assembly, and then reference this
assembly in a project, then when you create an instance of the "Derived"
class, the method named "Method" will not show up in the editor through
intellisense. AFAIK, this is the only way to accomplish hiding inherited
members from an end-developer. Of course, if the end-developer specified
that the "Method" should be called against an instance of the "Derived"
class, although they will not get intellisense to complete the code, it will
compile since the method does exist. This is the reason why the
"NotSupportedException" is pitched.

using System;
using System.ComponentModel;

namespace MyNamespace
{
public class Base : System.Object
{
public void Method()
{
// Do something.
}
}

public class Derived : Base
{
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
public new void Method()
{
throw (new NotSupportedException("This method is not supported."));
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

DanielF said:
I would like to find a way to completely hide selected methods of a base
class when inheriting from that base class. I know how to override a method
and replace a base class method using the "new" modifier on the method, but
then the method of the derived class shows up. I would like to be able to
completely hide a method so that it doesn't show up at all in an application
that instantiates the derived class. Any help would be appreciated.
 
T

Tim Wilson

Can you post some code? Post a reasonable code snippet from the base and
derived classes.

--
Tim Wilson
..Net Compact Framework MVP

drumred said:
Could you please help with a reverse problem. I have created a public class
with several public methods in it. I have derived a new class from the base
class. Intellisense does not "see" all the base class methods, though all
were made Public. I've even commented out many of the base class methods and
the derived class still shows theses methods. It seems that intellisense
isn't updating.

TIA, thanks is advance.

drumred

DanielF said:
OK, thanks - that does the trick!.

Tim Wilson said:
If you compile the following code into an assembly, and then reference this
assembly in a project, then when you create an instance of the "Derived"
class, the method named "Method" will not show up in the editor through
intellisense. AFAIK, this is the only way to accomplish hiding inherited
members from an end-developer. Of course, if the end-developer specified
that the "Method" should be called against an instance of the "Derived"
class, although they will not get intellisense to complete the code, it will
compile since the method does exist. This is the reason why the
"NotSupportedException" is pitched.

using System;
using System.ComponentModel;

namespace MyNamespace
{
public class Base : System.Object
{
public void Method()
{
// Do something.
}
}

public class Derived : Base
{
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
public new void Method()
{
throw (new NotSupportedException("This method is not supported."));
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

I would like to find a way to completely hide selected methods of a base
class when inheriting from that base class. I know how to override a
method
and replace a base class method using the "new" modifier on the method,
but
then the method of the derived class shows up. I would like to be able to
completely hide a method so that it doesn't show up at all in an
application
that instantiates the derived class. Any help would be appreciated.
 
Ad

Advertisements

G

Guest

Tim,

I regress. I am creating an instance of a new class. Here is a code
snippet.

Public Class FileControl
Public Sub Joe(ByVal str As String)
Return "Joe " & str
End Sub

'Public Sub Mike(ByVal str As String)
' Return "Mike" & str
'End Sub
End Class

Public Class frmMain
Dim mFileControl As FileControl
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim str As String
str = mFileControl.Joe("Builder")
str = mFileControl.Mile("Builder")
End Sub
End Class

In this case Visual Studio 2005 is telling me that Joe is not a member of
base class FileControl. Also, Mike, that I created earlier and now comment
out, shows up in Intellisense. It seems like VS isn't responding to changes
made in my program.

Thanks, drumred




Tim Wilson said:
Can you post some code? Post a reasonable code snippet from the base and
derived classes.

--
Tim Wilson
..Net Compact Framework MVP

drumred said:
Could you please help with a reverse problem. I have created a public class
with several public methods in it. I have derived a new class from the base
class. Intellisense does not "see" all the base class methods, though all
were made Public. I've even commented out many of the base class methods and
the derived class still shows theses methods. It seems that intellisense
isn't updating.

TIA, thanks is advance.

drumred

DanielF said:
OK, thanks - that does the trick!.

:

If you compile the following code into an assembly, and then reference this
assembly in a project, then when you create an instance of the "Derived"
class, the method named "Method" will not show up in the editor through
intellisense. AFAIK, this is the only way to accomplish hiding inherited
members from an end-developer. Of course, if the end-developer specified
that the "Method" should be called against an instance of the "Derived"
class, although they will not get intellisense to complete the code, it will
compile since the method does exist. This is the reason why the
"NotSupportedException" is pitched.

using System;
using System.ComponentModel;

namespace MyNamespace
{
public class Base : System.Object
{
public void Method()
{
// Do something.
}
}

public class Derived : Base
{
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
public new void Method()
{
throw (new NotSupportedException("This method is not supported."));
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

I would like to find a way to completely hide selected methods of a base
class when inheriting from that base class. I know how to override a
method
and replace a base class method using the "new" modifier on the method,
but
then the method of the derived class shows up. I would like to be able to
completely hide a method so that it doesn't show up at all in an
application
that instantiates the derived class. Any help would be appreciated.
 
G

Guest

1. You're returning data from a Sub - does that even compile?
2. Is your "FileControl" class in a separate assembly? If so, is it a
designer-supported assembly? I've seen this behavior when I've got multiple
different copies of the same assembly (like an old one in the designer
folder).

-Chris


drumred said:
Tim,

I regress. I am creating an instance of a new class. Here is a code
snippet.

Public Class FileControl
Public Sub Joe(ByVal str As String)
Return "Joe " & str
End Sub

'Public Sub Mike(ByVal str As String)
' Return "Mike" & str
'End Sub
End Class

Public Class frmMain
Dim mFileControl As FileControl
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim str As String
str = mFileControl.Joe("Builder")
str = mFileControl.Mile("Builder")
End Sub
End Class

In this case Visual Studio 2005 is telling me that Joe is not a member of
base class FileControl. Also, Mike, that I created earlier and now
comment
out, shows up in Intellisense. It seems like VS isn't responding to
changes
made in my program.

Thanks, drumred




Tim Wilson said:
Can you post some code? Post a reasonable code snippet from the base and
derived classes.

--
Tim Wilson
..Net Compact Framework MVP

drumred said:
Could you please help with a reverse problem. I have created a public class
with several public methods in it. I have derived a new class from the base
class. Intellisense does not "see" all the base class methods, though
all
were made Public. I've even commented out many of the base class
methods and
the derived class still shows theses methods. It seems that
intellisense
isn't updating.

TIA, thanks is advance.

drumred

:

OK, thanks - that does the trick!.

:

If you compile the following code into an assembly, and then
reference this
assembly in a project, then when you create an instance of the "Derived"
class, the method named "Method" will not show up in the editor through
intellisense. AFAIK, this is the only way to accomplish hiding inherited
members from an end-developer. Of course, if the end-developer specified
that the "Method" should be called against an instance of the "Derived"
class, although they will not get intellisense to complete the
code, it will
compile since the method does exist. This is the reason why the
"NotSupportedException" is pitched.

using System;
using System.ComponentModel;

namespace MyNamespace
{
public class Base : System.Object
{
public void Method()
{
// Do something.
}
}

public class Derived : Base
{
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
public new void Method()
{
throw (new NotSupportedException("This method is not supported."));
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

I would like to find a way to completely hide selected methods of
a base
class when inheriting from that base class. I know how to
override a
method
and replace a base class method using the "new" modifier on the method,
but
then the method of the derived class shows up. I would like to be able to
completely hide a method so that it doesn't show up at all in an
application
that instantiates the derived class. Any help would be
appreciated.
 
Ad

Advertisements

G

Guest

ctacke,

Thanks, I blew away old copies of assembly and am now updating in
Intellisense and able to use methods from the mFileControl class.

Regards, drumred

1. You're returning data from a Sub - does that even compile?
2. Is your "FileControl" class in a separate assembly? If so, is it a
designer-supported assembly? I've seen this behavior when I've got multiple
different copies of the same assembly (like an old one in the designer
folder).

-Chris


drumred said:
Tim,

I regress. I am creating an instance of a new class. Here is a code
snippet.

Public Class FileControl
Public Sub Joe(ByVal str As String)
Return "Joe " & str
End Sub

'Public Sub Mike(ByVal str As String)
' Return "Mike" & str
'End Sub
End Class

Public Class frmMain
Dim mFileControl As FileControl
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim str As String
str = mFileControl.Joe("Builder")
str = mFileControl.Mile("Builder")
End Sub
End Class

In this case Visual Studio 2005 is telling me that Joe is not a member of
base class FileControl. Also, Mike, that I created earlier and now
comment
out, shows up in Intellisense. It seems like VS isn't responding to
changes
made in my program.

Thanks, drumred




Tim Wilson said:
Can you post some code? Post a reasonable code snippet from the base and
derived classes.

--
Tim Wilson
..Net Compact Framework MVP

Could you please help with a reverse problem. I have created a public
class
with several public methods in it. I have derived a new class from the
base
class. Intellisense does not "see" all the base class methods, though
all
were made Public. I've even commented out many of the base class
methods
and
the derived class still shows theses methods. It seems that
intellisense
isn't updating.

TIA, thanks is advance.

drumred

:

OK, thanks - that does the trick!.

:

If you compile the following code into an assembly, and then
reference
this
assembly in a project, then when you create an instance of the
"Derived"
class, the method named "Method" will not show up in the editor
through
intellisense. AFAIK, this is the only way to accomplish hiding
inherited
members from an end-developer. Of course, if the end-developer
specified
that the "Method" should be called against an instance of the
"Derived"
class, although they will not get intellisense to complete the
code,
it will
compile since the method does exist. This is the reason why the
"NotSupportedException" is pitched.

using System;
using System.ComponentModel;

namespace MyNamespace
{
public class Base : System.Object
{
public void Method()
{
// Do something.
}
}

public class Derived : Base
{
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
public new void Method()
{
throw (new NotSupportedException("This method is not
supported."));
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

I would like to find a way to completely hide selected methods of
a
base
class when inheriting from that base class. I know how to
override a
method
and replace a base class method using the "new" modifier on the
method,
but
then the method of the derived class shows up. I would like to be
able to
completely hide a method so that it doesn't show up at all in an
application
that instantiates the derived class. Any help would be
appreciated.
 

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