Protecting methods of a DLL [duplicate]

1

I have a DLL that has several internal methods, I want to protect these internal methods so that they are called only by the DLL itself.

Is there any way to define which methods can be called externally from the DLL?

    
asked by anonymous 22.02.2017 / 20:25

1 answer

2

Yes, you should use internal for each method that can only be called by DLL.

The whole class can be internal as well. In fact this is the default.

It can be used with protected also, since this restrictor has to do with inheritance and not with simple visibility.

Something like this:

public class Tricycle {
    //só pode ser acessado por tipos dentro da DLL
    internal void Pedal() { }
    private int wheels = 3;

    //pode ser acessado por uma classe qualquer que derive desta, ou tipos desta DLL.
    protected internal int Wheels {
        get { return wheels; }
    }
}

I placed it on GitHub for future reference.

    
22.02.2017 / 20:28