469,928 Members | 1,875 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

Exposing internal members of an assembly

Hi,

I am trying to have a set of base classes and interfaces of an
application framework in their own assembly. That way, concrete
implementations of the API will reference that assembly and implement
the abstract classes and interfaces.

The problem is that some parts of the API are "internal" in the sense
that they are internal to the implementation. If I declare these parts
as internal in the API, the implementations will not be able to access
them.

The reason behind using "internal" members is to eliminate the need for
the proxy design pattern so I can pass objects between the implemation
and the GUI directly whilst ensuring that the appropriate access levels
are maintained.

Any thoughts?

Thank you,

Apr 20 '06 #1
5 1878
In "Programming .Net Components, 2nd Edition" (O'Reilly, July 2005, ISBN
0-596-10207-0) Juval Lowy shows how to do just want you want, assuming you
are in C# 2.0 (2005).

Section 2.2.8 of his book talks about a new attribute called
InteralsVisibleTo. In the AssemblyInfo.cs file, add this attribute:

[assembly: InternalsVisibleTo("YourDllOrExe")]

Any clients in the assemblies YourDllOrExe.EXE or YourDllOrExe.DLL will be
able to use any classes in your original dll and call both public and
internal members.

Haven't tried this yet myself, just happened to read about it last night so
it was good timing. It's more meant for situations where for whatever reason
a team decides to break a single DLL into multiple DLLs but parts in
different DLLs rely on internal members from the original.

Personally I think you ought to think about your design a bit, as you are
essentially exposing internal members and circumventing the whole of idea of
it being internal, but if you insist, well above is a way to do it.

Robert

<mm******@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi,

I am trying to have a set of base classes and interfaces of an
application framework in their own assembly. That way, concrete
implementations of the API will reference that assembly and implement
the abstract classes and interfaces.

The problem is that some parts of the API are "internal" in the sense
that they are internal to the implementation. If I declare these parts
as internal in the API, the implementations will not be able to access
them.

The reason behind using "internal" members is to eliminate the need for
the proxy design pattern so I can pass objects between the implemation
and the GUI directly whilst ensuring that the appropriate access levels
are maintained.

Any thoughts?

Thank you,


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Apr 20 '06 #2
Thanks a lot for your reply. Although your solution works, the base
assembly (Framework API) must be aware of its clients which is not
really practical.

Regarding the design, the problem is that the implementation must
specify methods that are internal to itself, so its kinda weird.

I found a possible but cumbersome solution and that is to use "modules"
which are assemblies without manifests. Basically, I can make a module
and include in an assembly and the assembly would have access to the
module's internal members. The problem with this is that it can only be
done with the command line compiler. VS 2005 doesn't support it.

Apr 20 '06 #3
<mm******@gmail.com> wrote:
I am trying to have a set of base classes and interfaces of an
application framework in their own assembly. That way, concrete
implementations of the API will reference that assembly and implement
the abstract classes and interfaces.

The problem is that some parts of the API are "internal" in the sense
that they are internal to the implementation. If I declare these parts
as internal in the API, the implementations will not be able to access
them.

The reason behind using "internal" members is to eliminate the need for
the proxy design pattern so I can pass objects between the implemation
and the GUI directly whilst ensuring that the appropriate access levels
are maintained.

Any thoughts?


So you want the derived classes to have access to the members in the
base classes, but you don't want other classes to have access to those
members? If so, you just need protected access.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 20 '06 #4
That will deny derived classes from using each other which is what the
framework is all about. The primary problem is that the framework API
will reside in a different assembly.
For example, I can use the "protected internal" access level but that
would mean that classes in the implementation will not have access to
"protected internal" members.

Apr 20 '06 #5
<mm******@gmail.com> wrote:
That will deny derived classes from using each other which is what the
framework is all about.
Ah - that wasn't clear.
The primary problem is that the framework API will reside in a different
assembly.


It sounds like the members should basically be public then. Yes,
there's a risk that components which shouldn't use those members will
use them - but I suspect the risk is small in reality.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Andrew R. Thomas-Cramer | last post: by
3 posts views Thread by Dave Veeneman | last post: by
7 posts views Thread by Jesper | last post: by
6 posts views Thread by Sgt. Sausage | last post: by
6 posts views Thread by Plamen Doykov | last post: by
4 posts views Thread by =?Utf-8?B?QkogU2FmZGll?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.