Question

I have three classes in my project, whose ultimate goal is to create a single dll:

  1. public class Main
  2. public class Helper1
  3. public static class Helper2

Those classes obviusly contain methods & variables that are either private or public. How do I make the components of the helper classes invisible for an end user in a dll, but visible for the Main class? I have a feeling this might be part of some broader programming concept that I am unaware of, so I'd be grateful for some links describing that in more detail as well.

public class Main
{
    public void MainMethod()
    {
        Helper1 h = new Helper1();
        h.DoSomething()
        Helper2.DoSomethingElse();
    }
}

public class Helper1
{
    public void DoSomething()
    {
        //some code
    }
}

public static class Helper2
{
    public static void DoSomethingElse()
    {
        //some code
    }
}

So, what I want to achieve, is to only allow the user who references my dll to be able to create an instance of the Main class and call the MainMethod(). I don`t want them to be able to create helper classes instances, neither do I want them to be able to call their methods.

Était-ce utile?

La solution

Use the internal access modifier for them. For instance:

internal class Helper1
{
    public void DoSomething()
    {
        //some code
    }
    ...
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top