If everything is within the same class (only with the comments this is clear) local function is the solution . Obviously you are limited to a method, you can not make a method accessible by a list of methods.
Everything must be within scope or specified scope in general, not specific, unless you make an external tool that is required to go through every build. One of the reasons for creating the .NET Compiler Platform is precisely to make this type of tool. But of course if not go through it will not prohibit anything.
Remembering that forcing or forbidding always occurs when the programmer wants to follow the standard protocols, if he wants to go over it, he always can. This would be a protection against an inadvertent error, not security against fraud.
If the local function does not match, the maximum the standard compiler allows is to prohibit its calling outside the class ( private
), outside the class hierarchy ( protected
) or outside the assembly ( internal
) or a combination of the last two, or you can limit it further and allow a method of the class to be the only one to access a function function . But you can not say nominally who can access.
You can say that can be accessed by some other assembly with an attribute .