In C#, how to restrict who can call a method at compile time

前端 未结 4 1395
北恋
北恋 2021-01-15 05:25

In C#, is it possible to restrict who can call a method at compile time?

I\'ve looked into directives, but that didn\'t work since I can\'t assign values to symbols.

4条回答
  •  暖寄归人
    2021-01-15 05:53

    The quick answer will be: No this isn't possible, and if you need to do it, you're Doing It Wrong.

    How would this even work? Does it depend who who's running the code or who wrote it?

    Edit There's kind of a way using InternalsVisibleTo and restricting accessing in source control to the assemblies that InternalsVisibleTo is specified for. See Jordão's answer

提交回复
热议问题