473,395 Members | 1,681 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,395 software developers and data experts.

Exposing internal classes as properties?

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 populated with Address
objects. This property has Public accessibility, as well.

To keep the assembly interface clean, I want to hide the objects on which
the property is based (The Address and Addresses objects) from users outside
the assembly. Declaring them as Internal would do the trick, but the
compiler throws an "Inconsistent Accessibility" exception, since the
property is Public, and the objects on which it is based are Internal.

Is there any way around this issue? Is there some other way to expose the
objects only through the property based on them?

Thanks.

--
Dave Veeneman
Chicago
Nov 15 '05 #1
3 5714
n!
> 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 populated with Address
objects. This property has Public accessibility, as well.
If the object is internal, making it available as a public property makes no
sense as the user can access the property but not the type returned! :)
Is there any way around this issue? Is there some other way to expose the
objects only through the property based on them?


Provide an IAddress interface that your internal class inherits and have the
property return an IAddress interface rather than the object type (example
follows):

n!

// Note this isn't a complete example...

public class Customer
{
private Address address = null;

public IAddress Address
{
get
{
return address;
}
}
}

public interface IAddress
{
// Interface definition
}

internal class Address : IAddress
{
// Implementation...
}
Nov 15 '05 #2
If your Addresses/Address object are going to be exposed via a property,
they have to be declared somewhere, why not create a public class or
interface and inherit from that, see example below:

//Create Abstract Bar class for FooBar to inherit
public abstract class Bar
{
private int barCount;

public int BarCount {get{return barCount;}set{barCount = value;}}
}

public class Foo
{
private Bar bar = new FooBar(10);

//Expose a Bar, from our private FooBar
public Bar FooBarObject {get{return bar;}}

private class FooBar: Bar
{
//Constructor only visible to Foo
internal FooBar(int cnt)
{
this.BarCount = cnt;
}
}
}

"Dave Veeneman" <da****@nospam.com> wrote in message
news:ea**************@TK2MSFTNGP10.phx.gbl...
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 populated with Address
objects. This property has Public accessibility, as well.

To keep the assembly interface clean, I want to hide the objects on which
the property is based (The Address and Addresses objects) from users outside the assembly. Declaring them as Internal would do the trick, but the
compiler throws an "Inconsistent Accessibility" exception, since the
property is Public, and the objects on which it is based are Internal.

Is there any way around this issue? Is there some other way to expose the
objects only through the property based on them?

Thanks.

--
Dave Veeneman
Chicago

Nov 15 '05 #3
Thanks for the quick replies. What I take away from this is: If I am going
to declare a property ObjectProperty of type SomeObject, where SomeObject is
a class I have defined, then any user of that property is going to need to
see the SomeObject class. Otherwise, the user can't get to any of the
ObjectProperty 'sub-properties' contained in the SomeObject class.

"It seems so simple when uoy put it that way..." --Homer Simpson

--
Dave Veeneman
Chicago
Nov 15 '05 #4

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

Similar topics

4
by: L. Bushkin | last post by:
I have a C# class that is declared as internal. I do not want it to be visible outside of the library of code that I am implementing. However, I do want to be able to serialize it to XML under...
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...
3
by: FredC | last post by:
How do you make a program's properties and methods availale so that other programs can "connect" to them at design time and then use them at run time?
8
by: Dave A | last post by:
I have a class called 'PrimaryKey' that represents the primary key of a table. PrimaryKeys can only be created and the class only implements .ToString(). The PrimaryKey class internally stores...
0
by: Symon | last post by:
Hi everyone, I'm writing a webservice where I'm trying to expose a framework that contains a number of classes which have read-only properties. I want to expose data-transfer proxies of these...
3
by: Dave | last post by:
Please - anyone that can help. I am getting confusing results while trying to expose a collection from a web service. I have a webservice in which a web method accepts a collection as a...
5
by: mmkhajah | last post by:
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...
1
by: Adam Clauss | last post by:
First, I have ComVisible set to true for the entire assembly. I have (abstract) base class A. There are interfaces IA and IAEvents for accessing properties of this object and exposing events. ...
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...

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.