Class Access Modifiers internal

I have created a class called ClientCapsule which contains data about the client, this class contains another class i created in the same scope called ClientInformation .

i don't want to allow creation of ClientInformation class outside of the ClientCapsule, yet i want to allow ClientInformation instance as a member of ClientCapsule and allow access to ClientInformation members when creating ClientCapsule instance.

here is an example of what i'm trying to do:

namespace AdminServer
{
    public enum ClientOperation
    {
        Subscribe,
        GetTables
    }

    [Serializable]
    internal class ClientInformation
    {

    }

    [Serializable]
    public class ClientCapsule
    {


        public readonly IPHostEntry clientMetaData;

        public readonly ClientOperation clientRequestedOperation;

        public readonly ClientInformation clientInfo;
    }
}

So i won't be able to do out side of this scope: ClientInformation object = new ClientInformation()

BUT i would be able to do: ClientCapsule object = new ClientCapsule(),object.ClientInformation.members;

but i'm getting an error:

Inconsistent accessibility field type ClientInformation is less accessible than field ClientCapsule.clientInfo

Jon Skeet
people
quotationmark

It sounds like you need ClientInformation to be a public class - just give it an internal constructor, preventing instantiation from elsewhere.

people

See more on this question at Stackoverflow