473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2002
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew R. Thomas-Cramer | last post by:
Can I simply mark a class as internal, or should I change all its public members to internal as well? If I can mark the class only as internal, it makes modifications easy.
3
by: Dave Veeneman | last post by:
Is there a way to expose an internal class as a public property of its parent object? Let's say I have a Customer object with Public accessibility. It has an Addresses collection property that it...
7
by: Jesper | last post by:
I need to grant a class access to protected fields of another class in the way its possible in C++ with the friend keyword. However I would like to keep the class protected towards other class...
19
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and...
6
by: Sgt. Sausage | last post by:
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...
6
by: Plamen Doykov | last post by:
Hi all I have converted a simple project from ASP.NET 1 to 2.0 with the latest prerelease of Visual Studio 2005. The problem is I can't access internal members from the code behind. It gives:...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
4
by: bob_jenkins | last post by:
C# allows code to be generated, but the generated code is in its own assembly. Is there a way for that generated code to access internal classes in the assembly that produced it? To have the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.