473,471 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inherit an internal class to a public class

Hi everybody,

I have two assemblies. The first is used by the client sites and
provides some public classes using internal classes (access must be
restrictive). The second is an "administrative" assembly which add
functionalities to the current classes (free access to the classes).

This assembly have access to the internal classes thanks to friendly
assemblies.
http://www.c-sharpcorner.com/UploadF...7PM/reuse.aspx

So i want to inherit internal classes from the first assembly to
public classes in the second assembly, but Visual Studio can't compile
it.

namespace Assembly1
{
internal class MyClass
{
...
}
}

namespace Assembly2
{
public class MyClass : Assembly2.MyClass
{
...
}
}

Maybe someone have a solution ?

Thanks

Aug 21 '07 #1
3 4534
<gu*******@gmail.comwrote:
So i want to inherit internal classes from the first assembly to
public classes in the second assembly, but Visual Studio can't compile
it.
You can't do this whether they're in the same assembly or not. From the
ECMA spec for C# 2, section 17.1.2.1:

<quote>
The direct base class (and any type arguments) of a class type shall be
at least as accessible as the class type itself (§10.5.4). For example,
it is a compile-time error for a public class to derive from a private
or internal class.
</quote>

If you think about it, it makes sense - clients of your public class
would be able to "see" that class from whatever assembly they were in,
but may not be able to "see" its base class. How would they know what
members it had etc?

--
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
Aug 21 '07 #2

<gu*******@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
Hi everybody,

I have two assemblies. The first is used by the client sites and
provides some public classes using internal classes (access must be
restrictive). The second is an "administrative" assembly which add
functionalities to the current classes (free access to the classes).

This assembly have access to the internal classes thanks to friendly
assemblies.
http://www.c-sharpcorner.com/UploadF...7PM/reuse.aspx

So i want to inherit internal classes from the first assembly to
public classes in the second assembly, but Visual Studio can't compile
it.

namespace Assembly1
{
internal class MyClass
{
...
}
}

namespace Assembly2
{
public class MyClass : Assembly2.MyClass
{
...
}
}

Maybe someone have a solution ?
How about this:
[assembly: InternalsVisibleTo("Assembly2")]
namespace Assembly1
{
internal class ImplementationDetails
{
...
}
}

namespace Assembly2
{
public interface IMyClass
{
...
}

class MyClass : Assembly2.ImplementationDetails, IMyClass
{
...
}
}
Aug 22 '07 #3

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:OM**************@TK2MSFTNGP03.phx.gbl...
>
<gu*******@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
>Hi everybody,

I have two assemblies. The first is used by the client sites and
provides some public classes using internal classes (access must be
restrictive). The second is an "administrative" assembly which add
functionalities to the current classes (free access to the classes).

This assembly have access to the internal classes thanks to friendly
assemblies.
http://www.c-sharpcorner.com/UploadF...7PM/reuse.aspx

So i want to inherit internal classes from the first assembly to
public classes in the second assembly, but Visual Studio can't compile
it.

namespace Assembly1
{
internal class MyClass
{
...
}
}

namespace Assembly2
{
public class MyClass : Assembly2.MyClass
{
...
}
}

Maybe someone have a solution ?

How about this:
[assembly: InternalsVisibleTo("Assembly2")]
namespace Assembly1
{
internal class ImplementationDetails
{
...
}
}

namespace Assembly2
{
public interface IMyClass
{
...
}

class MyClass : Assembly2.ImplementationDetails, IMyClass
oops, that was supposed to be Assembly1.ImplementationDetails
{
...
}
}


Aug 27 '07 #4

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

Similar topics

2
by: Adam | last post by:
I am trying to inherit from MessageBox and i get error in compilation time. The code is: public class MyMessageBox : MessageBox { public static DialogResult Show(int errorCode) { return...
4
by: Slavyan | last post by:
(I just started to learn C#.NET) What's the syntax in c# for a class to inherit more than one class. I know following syntax: public class MyClass : MyOtherClass { } but I need to inherit...
6
by: Mohammad-Reza | last post by:
I wrote a component using class library wizard. In my component i want to in order to RightToLeft property do some works. I can find out if user set this property to Yes or No, But if He/She set it...
5
by: Mike L | last post by:
This is my first attempt at inheriting a class. I want to inherit textbox class to my derived class ClassNum. ClassNum will override the TextChanged, Leave, KeyPress and Enter methods. So,...
1
by: daniel | last post by:
i wirte a "class b" to inherit DataColumnCollection, but it show a error message that is 'method of DataColumnCollection is not anyone overloadding to use zero of argument' The following it is...
7
by: Frank | last post by:
Hi, a question probably asked before, but I can't find the answers. Base class X, classes A, B and C inherit class X. In class A I do not want to inherit property (or function or method) P1....
3
by: J | last post by:
I tried to inherit 'Shot' class from 'Image' class, only to fail. It gives me the CS0122 error, which says that it can't access 'System.Drawing.Image.Image()'. What am I missing? using...
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)...
5
by: Redivivus | last post by:
Hi How to inherit from System.Data.DataRow? class ItemRow: DataRow { public ItemRow(DataRowBuilder rb):base(rb){} }
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.