By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Error with "internal interface"

P: n/a
I am facing a problem. My project is composed of several assemblies. In one
of them -the backend- I have several internal classes that must implement an
interface. These internal classes are only used by one master class that is
public.

I am able to declare the interface as "internal interface" without problem
but when I attempt to use it by declaring a class that implements it, if I
declare the implemented interface members as "internal" (they are supposed
to be seen only within the assemly) I get an error that it is not
implemented because of "wrong return type or wrong visibility" so basically
it is forcing me to use "public" which I don't want because I don't want
those methods to be seen outside.

Or... perhaps the public gets "downgraded" if you use an "internal"
attribute in the class declaration, at least that is what I am hoping for
but makes the notation a bit confusing.

Emilio
Jun 14 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jun 14, 1:39 pm, "~~~ .NET Ed ~~~" <tiredofs...@abolishspam.now>
wrote:
I am facing a problem. My project is composed of several assemblies. In one
of them -the backend- I have several internal classes that must implement an
interface. These internal classes are only used by one master class that is
public.

I am able to declare the interface as "internal interface" without problem
but when I attempt to use it by declaring a class that implements it, if I
declare the implemented interface members as "internal" (they are supposed
to be seen only within the assemly) I get an error that it is not
implemented because of "wrong return type or wrong visibility" so basically
it is forcing me to use "public" which I don't want because I don't want
those methods to be seen outside.
That's because all interface members are public by default.
Or... perhaps the public gets "downgraded" if you use an "internal"
attribute in the class declaration, at least that is what I am hoping for
but makes the notation a bit confusing.
Nope, the members are still public.

However, if the class itself is internal, that's pretty much
irrelevant as no-one outside the assembly will be able to see it
anyway.

Jon

Jun 14 '07 #2

P: n/a
Hi,

If those classes are only used by one class, why don't you declare them as
private to the master class?

/In the same vein you can declare your interface inside the Master class.
But even so it might be visible from the outside using Master.Interface

Now, if you change the interface for an abstract class inside the Master you
can get what you want:
public class Master
{
abstract class A
{
abstract public void Me();

}
class B : A
{
public override void Me()
{
throw new Exception("The method or operation is not
implemented.");
}
}
}

"~~~ .NET Ed ~~~" <ti*********@abolishspam.nowwrote in message
news:ua**************@TK2MSFTNGP04.phx.gbl...
>I am facing a problem. My project is composed of several assemblies. In one
of them -the backend- I have several internal classes that must implement
an interface. These internal classes are only used by one master class that
is public.

I am able to declare the interface as "internal interface" without problem
but when I attempt to use it by declaring a class that implements it, if I
declare the implemented interface members as "internal" (they are supposed
to be seen only within the assemly) I get an error that it is not
implemented because of "wrong return type or wrong visibility" so
basically it is forcing me to use "public" which I don't want because I
don't want those methods to be seen outside.

Or... perhaps the public gets "downgraded" if you use an "internal"
attribute in the class declaration, at least that is what I am hoping for
but makes the notation a bit confusing.

Emilio

Jun 14 '07 #3

P: n/a
"~~~ .NET Ed ~~~" <ti*********@abolishspam.nowschrieb im Newsbeitrag
news:ua**************@TK2MSFTNGP04.phx.gbl...
I am able to declare the interface as "internal interface" without problem
but when I attempt to use it by declaring a class that implements it, if I
declare the implemented interface members as "internal" (they are supposed
to be seen only within the assemly) I get an error that it is not
implemented because of "wrong return type or wrong visibility" so
basically it is forcing me to use "public" which I don't want because I
don't want those methods to be seen outside.
If you want the methods to remain internal you have to implement them
explicitly, that is by naming the interface in the member:

public class Class : Interface
{
//This member is only accessible by cast to the interface
void Interface.Method()
{
//This call is made if the following declaration is present
Method();
//Or simpöy put here the implementation
}

//Make it accessible without cast to interface
internal void Method()
{
...
}
}

Now you have a public class wich implements a interface, wich is only
accessible internal.

But if the class itself is internal, all members even public will only be
accessible internal.

Christof
Jun 14 '07 #4

P: n/a
>I am able to declare the interface as "internal interface" without
>problem
but when I attempt to use it by declaring a class that implements it, if
I
declare the implemented interface members as "internal" (they are
supposed
to be seen only within the assemly) I get an error that it is not
implemented because of "wrong return type or wrong visibility" so
basically
it is forcing me to use "public" which I don't want because I don't want
those methods to be seen outside.

That's because all interface members are public by default.
>Or... perhaps the public gets "downgraded" if you use an "internal"
attribute in the class declaration, at least that is what I am hoping for
but makes the notation a bit confusing.

Nope, the members are still public.

Didn't we just discuss this exact issue to death earlier this week?

http://groups.google.com/group/micro...56d1646a1e150b

Jun 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.