Is there a way to restrict access to a public method to only a specific class in C#?

后端 未结 5 1470
萌比男神i
萌比男神i 2021-01-12 06:30

I have a class A with a public method in C#. I want to allow access to this method to only class B. Is this possible?

UPDATE:

This is what i

5条回答
  •  情歌与酒
    2021-01-12 06:56

    You can restrict method/class access in this way:

    [StrongNameIdentityPermissionAttribute(SecurityAction.Demand, PublicKey="…hex…", Name="App1", Version="0.0.0.0")]
    public class Class1 { } 
    

    Take a look here http://msdn.microsoft.com/en-us/library/c09d4x9t.aspx for more info.

    Managed code offers several ways to restrict method access:
    ...

    • Limit the method access to callers of a specified identity--essentially, any particular evidence (strong name, publisher, zone, and so on) you choose.

提交回复
热议问题