Prevent an interface reference to an internal class

T

Tom

Hi

I defined a class, which contains a private class with properties to an
internal field. The private class is shown by an interface to outside of the
outer class. What can I do to prevent, that a variable of the interface typ
can be defined to make a reference to the internal class. Otherwise I want to
have access to the internal fields of the inner class directly from outside.

I make an example to give you more clarity:
Config, the outer class
Datas, the private class within Config, accessable over the property CFDATA
by the interface IDatas
Keyset, the field within Datas accessable by a property

Now I want to do the following:
Config.CFData.Keyset = 35; // direct-access

The following should not be possible:
Config.IData tmpcfg = Config.CFData; // define a reference
tmpcfg.Keyset = 35; // access by reference
....or the internal field Keyseet is not changed, when an access by reference
is made

Thanks
Tom
 
L

Lasse Vågsæther Karlsen

Tom said:
Hi

I defined a class, which contains a private class with properties to an
internal field. The private class is shown by an interface to outside of the
outer class. What can I do to prevent, that a variable of the interface typ
can be defined to make a reference to the internal class. Otherwise I want to
have access to the internal fields of the inner class directly from outside.

I make an example to give you more clarity:
Config, the outer class
Datas, the private class within Config, accessable over the property CFDATA
by the interface IDatas
Keyset, the field within Datas accessable by a property

Now I want to do the following:
Config.CFData.Keyset = 35; // direct-access

The following should not be possible:
Config.IData tmpcfg = Config.CFData; // define a reference
tmpcfg.Keyset = 35; // access by reference
...or the internal field Keyseet is not changed, when an access by reference
is made

Thanks
Tom

Why exactly should the above code not be possible? I'm probably dense
but it seems you want to prevent outside access through a property, but
allow access directly to the field...
 
J

Jon Skeet [C# MVP]

I defined a class, which contains a private class with properties to an
internal field. The private class is shown by an interface to outside of the
outer class. What can I do to prevent, that a variable of the interface typ
can be defined to make a reference to the internal class. Otherwise I want to
have access to the internal fields of the inner class directly from outside.

I'm afraid I'm really not following you. Could you give a complete
example, and explain *why* you want to prohibit certain behaviour?

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top