c# - Different levels of access to methods -
c# - Different levels of access to methods -
situation:
i'm creating 2 libraries: x1.dll , x2.dll. created , amended separately , projects couldn't combined 1 solution.
x1.dll contains definition of class c1. x2.dll contains definition of class c2.
x2.dll references x1.dll.
class c1 has method m1(). method used in x2.dll , reason why m1() made public method.
i distribute x1.dll , x2.dll other developers. not want them phone call m1() - can whatever want c1 instances, not touch m1(). @ same time, m1() public because have able phone call in x2.dll.
question:
what best way organize m1() in order create available me still not merge projects x1.dll , x2.dll?
there plenty of awkward solutions making m1() m1(string secretecode) , hardcode secretecode i'm 1 can pass right argument.
but best practice accomplish goal?
thanks suggestions!
make m1()
internal
, add together internalsvisibletoattribute
on assembly allow x2.dll
phone call x1.dll
's internal
code. solution makes all internal
code in x1
visible in x2
, you're sure no 1 else going phone call m1()
.
from documentation:
ordinarily, types , members internal scope (in c#) , friend scope (in visual basic) visible in assembly in defined. internalsvisibletoattribute attribute makes them visible types in specified assembly, known friend assembly.
simply add together [assembly:internalsvisibleto("x2")]
assembly. if assembly signed, you'll need add together public key of strong name key [assembly:internalsvisibleto("x2, publickey=0000000000")]
this improve "secret code" because c# code easy decompile , secret won't secret long time!
c# .net
Comments
Post a Comment