473,770 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

protected internal interface

I know it's not possible, but I need a protected internal interface:

protected internal interface ISomeInterface{

// yadda yadda yadda

}

Basically, I need an interface that is completely accessable
from within the assembly (internal), but is not valid outside
the assembly except for derived objects that live outside
the assembly, but deriving from an object internal to the
assembly (protected).

With the existing interface scoping constraints, I can't do
this. I'm not allowed to declare a protected internal interface.

I've got an object that needs to expose one interface
publicly (easy to do), but internally to the assembly
needs to be accessable in a slightly different manner via
a slightly different interface.

Knowing that this can't be done via interfaces, does
anyone have any alternatives?

I can't believe that this is a really oddball request. Does
anyone have an explanation as to why an interface can't
be declared as "protected internal interface" ?


Nov 16 '05 #1
6 12000
Assembly 1:

public class Class2
{
protected internal interface IFoo
{
}
}
Assembly 2 referencing assembly 1:

class Bar : Class2
{
protected void Quux(Class2.IFo o f)
{
}
}
Is this what you mean? This is supported (the above compiles fine). Or do you mean something else?

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<QW************ @fe37.usenetser ver.com>

I know it's not possible, but I need a protected internal interface:

protected internal interface ISomeInterface{

// yadda yadda yadda

}

Basically, I need an interface that is completely accessable
from within the assembly (internal), but is not valid outside
the assembly except for derived objects that live outside
the assembly, but deriving from an object internal to the
assembly (protected).

With the existing interface scoping constraints, I can't do
this. I'm not allowed to declare a protected internal interface.

I've got an object that needs to expose one interface
publicly (easy to do), but internally to the assembly
needs to be accessable in a slightly different manner via
a slightly different interface.

Knowing that this can't be done via interfaces, does
anyone have any alternatives?

I can't believe that this is a really oddball request. Does
anyone have an explanation as to why an interface can't
be declared as "protected internal interface" ?

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #2

"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:Oy******** *****@tk2msftng p13.phx.gbl...
Assembly 1:

public class Class2
{
protected internal interface IFoo
{
}
}
Assembly 2 referencing assembly 1:

class Bar : Class2
{
protected void Quux(Class2.IFo o f)
{
}
}
Is this what you mean? This is supported (the above compiles fine). Or do

you mean something else?

Might be -- I'd have to try it out. I didn't know that interfaces
could be defined from *within* a class. I've been defining then
outside the class and implementing them within the classes.

I'll see if it gets me where I want to go.

BTW -- what does it mean to define an interface from
within a class. How is this different (other than possibly
allowing my scope issue to be solved) how is it different
than defining an interface outside the class.

It seems somhow, well ... wrong. The interface might be
implemented by several different classes. Why should it
be defined within one class and not another -- hence my
habit to declare them outside of classes.

Am I crazy?

You've got an example: protected void Quux(Class2.IFo o f)

which makes an (invalid) association in my mind between
Class2 and IFoo -- IFoo might also be implemented by
Class3, Class4 and Class5 -- why should it be tied to
Class2? I'd much rather have:

protected void Quux(IFoo f) without any knowledge of
Class2 -- ain't that the whole point of an interface? That
it *hides* the actual concrete object behind an interface
such that you don't care if it's a Class2 or Class3 or Class4,
just that it implements IFoo?



Nov 16 '05 #3
The concept of having the interafce as part of a class definition is stating that this interface onlt has meaning in terms of this class. As you had a rquirement that classes outside the assembly could only see the interface if they derived from a particular class (Class2?) then it seemed to fit your model.

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<br************ *@fe37.usenetse rver.com>
"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:Oy******** *****@tk2msftng p13.phx.gbl...
Assembly 1:

public class Class2
{
protected internal interface IFoo
{
}
}
Assembly 2 referencing assembly 1:

class Bar : Class2
{
protected void Quux(Class2.IFo o f)
{
}
}
Is this what you mean? This is supported (the above compiles fine). Or do

you mean something else?

Might be -- I'd have to try it out. I didn't know that interfaces
could be defined from *within* a class. I've been defining then
outside the class and implementing them within the classes.

I'll see if it gets me where I want to go.

BTW -- what does it mean to define an interface from
within a class. How is this different (other than possibly
allowing my scope issue to be solved) how is it different
than defining an interface outside the class.

It seems somhow, well ... wrong. The interface might be
implemented by several different classes. Why should it
be defined within one class and not another -- hence my
habit to declare them outside of classes.

Am I crazy?

You've got an example: protected void Quux(Class2.IFo o f)

which makes an (invalid) association in my mind between
Class2 and IFoo -- IFoo might also be implemented by
Class3, Class4 and Class5 -- why should it be tied to
Class2? I'd much rather have:

protected void Quux(IFoo f) without any knowledge of
Class2 -- ain't that the whole point of an interface? That
it *hides* the actual concrete object behind an interface
such that you don't care if it's a Class2 or Class3 or Class4,
just that it implements IFoo?


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #4

"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:es******** ******@TK2MSFTN GP11.phx.gbl...
The concept of having the interafce as part of a class definition is stating that this interface onlt has meaning in terms of this class. As you
had a rquirement that classes outside the assembly could only see the
interface if they derived from a particular class (Class2?) then it seemed
to fit your model.

I'm sorry -- maybe I didn't state it clearly.

What I said was:
Basically, I need an interface that is completely accessable
from within the assembly (internal), but is not valid outside
the assembly except for derived objects that live outside
the assembly, but deriving from an object internal to the
assembly (protected).


Which made perfect sense to me, but after re-reading
is a bit vague.

I need the interface to be implementable (?) by any
old object in the assembly -- but only accesseble
outside the assembly from objects that inherit from
within the assembly.

I *need*

Assembly1:

protected internal interface ISomeRandomInte rface
{
// yadda yadda yadda
}

public Class1: ISomeRandomInte rface
{
// yadda yadda yadda
}

public Class2: ISomeRandomInte rface
{
// yadda yadda yadda
}

public Class3: ISomeRandomInte rface
{
// yadda yadda yadda
}

Assembly2:

public Class11: Class1
{
//Has access to ISomeRandomInte rface
// it inherits from Class1
}

public Class22: Class2
{
//Has access to ISomeRandomInte rface
// it inherits from Class1
}

public Class99
{
// can't do anything with ISomeRandomInte rface
// it's internal to Assembly1 and this guy doesn't
// inherit from Assembly1
}

// nobody else has access because they're not
// in Assembly1 and they don't inherit from
// objects in Assembly1 that implement
// ISomeRandomInte rface.
It would be nice, but c# specifically does *not* allow
my:

protected internal interface ISomeRandomInte rface
{
// yadda yadda yadda
}

I'm stuck and looking for help. Your attempt at help
is appreciated , but it doesn't get me where I'm wanting
to go.

Thanks anyway!

Nov 16 '05 #5
Sgt. Sausage <no****@nowhere .com> wrote:

<snip>
I need the interface to be implementable (?) by any
old object in the assembly -- but only accesseble
outside the assembly from objects that inherit from
within the assembly.

I *need*


<snip>

What's the downside of just making it a public interface and letting
any class implement it?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
protected is only meaningful if it's used on members of a class.

to do what you want, you should use an abstract base class with all the
appropriate members declared as internal protected.

"Sgt. Sausage" wrote:

"Richard Blewett [DevelopMentor]" <ri******@devel op.com> wrote in message
news:es******** ******@TK2MSFTN GP11.phx.gbl...
The concept of having the interafce as part of a class definition is

stating that this interface onlt has meaning in terms of this class. As you
had a rquirement that classes outside the assembly could only see the
interface if they derived from a particular class (Class2?) then it seemed
to fit your model.

I'm sorry -- maybe I didn't state it clearly.

What I said was:
Basically, I need an interface that is completely accessable
from within the assembly (internal), but is not valid outside
the assembly except for derived objects that live outside
the assembly, but deriving from an object internal to the
assembly (protected).


Which made perfect sense to me, but after re-reading
is a bit vague.

I need the interface to be implementable (?) by any
old object in the assembly -- but only accesseble
outside the assembly from objects that inherit from
within the assembly.

I *need*

Assembly1:

protected internal interface ISomeRandomInte rface
{
// yadda yadda yadda
}

public Class1: ISomeRandomInte rface
{
// yadda yadda yadda
}

public Class2: ISomeRandomInte rface
{
// yadda yadda yadda
}

public Class3: ISomeRandomInte rface
{
// yadda yadda yadda
}

Assembly2:

public Class11: Class1
{
//Has access to ISomeRandomInte rface
// it inherits from Class1
}

public Class22: Class2
{
//Has access to ISomeRandomInte rface
// it inherits from Class1
}

public Class99
{
// can't do anything with ISomeRandomInte rface
// it's internal to Assembly1 and this guy doesn't
// inherit from Assembly1
}

// nobody else has access because they're not
// in Assembly1 and they don't inherit from
// objects in Assembly1 that implement
// ISomeRandomInte rface.
It would be nice, but c# specifically does *not* allow
my:

protected internal interface ISomeRandomInte rface
{
// yadda yadda yadda
}

I'm stuck and looking for help. Your attempt at help
is appreciated , but it doesn't get me where I'm wanting
to go.

Thanks anyway!

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
3428
by: Act | last post by:
Why is it suggested to not define data members as "protected"? Thanks for help!
8
2546
by: Carlos J. Quintero | last post by:
Hi, As you know the current keywords "protected internal" (C#) or "Protected Friend" (VB.Net) means "Protected Or internal" (C#) or "Protected Or Friend" (VB.Net), that is, the member is accesible from whichever types inside the assembly or from derived classes included those outside the assembly. The IL has a provision for the "family AND assembly" accesibility level, that is, a member is accesible from derived classes belonging to...
2
6062
by: Kolozs, Ãron | last post by:
Hi everybody, The C# compiler reports a Compiler Error CS0052 in the following situation: I declared a type marked as "internal": namespace MyNamespace { internal class MyInteralClass
8
4346
by: Steven Livingstone | last post by:
I know this is not supported, but i'm just looking for some reasoning and perhaps debate. Is there are reason why this is not supported as in the words of manhy a French poet "it's doing my head in". I simply wish to break some concrete (and circular) dependencies into interface dependences and decouple some of my classes. It is an internal coupling (almost) as i don't want some of these methods exposed to the outside world, only to...
4
6305
by: newbie120 | last post by:
Hi all maybe its just been a long day, but i have a question about call access modifiers in C#. Consider the following code. namespace Application { private class Class1 { int i;
86
4652
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or method can be defined by prefixing the declaration with the keywords: public, protected or private. Public declared items can be accessed everywhere."
16
3631
by: Fir5tSight | last post by:
Hi All, I have a small C#.NET program that is as follows: using System; class A { protected int x = 123; }
13
2826
by: Clive Dixon | last post by:
I am refactoring some code to move some base classes into a separate assembly. One of these base classes has a member property which is 'protected internal'. However when I move these base classes to another assembly, the compiler complains that the override in the derived class, also declared as 'protected internal', is trying to change the access modified from 'protected', which is clearly not the case. (I have checked the metadata in...
2
1979
by: jehugaleahsa | last post by:
Hello: I have a public abstract class. The concrete subclasses must pass an instance of an internal class to the abstract class' ctor. I like to make the constructors of my abstract classes protected. However, since it has a parameter that is of an internal type, I am forced to make it internal also. This is fine since no one outside my library can see it.
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.