问题
I have two different libraries which refereed the base library called base.dll. One library using for web platforms another one using for windows platform (WPF). I have to restrict restrict one public property in WPF platform but I want to access it in web platform. How can achieve this? I am trying condition compilation but I don’t know how to do exactly. Please help me
For Ex:- Base library:
public Class CommonClass{
public string CssClass
{
get;
set;
}
}
Referenced Library 1 (Web) – Referenced the base library, need to access CssClass in this library
Referenced Library 2: (WPF) - Referenced the base library, need to restrict CssClass in this library
回答1:
This actually sounds like a design flaw. You create a library and define which properties should be accessible by users of that library. Normally you don't hide specific properties from specific clients.
However, I think you can achieve what you want by making the property internal
and use the InternalsVisibleToAttribute in your base.dll
:
[assembly: InternalsVisibleTo("webplatformassembly")]
public Class CommonClass{
internal string CssClass
{
get;
set;
}
}
This way no client can see that property, except those mentioned in a InternalsVisibleTo
attribute.
See also: Friend Assemblies (C# and Visual Basic)
来源:https://stackoverflow.com/questions/44302553/how-can-i-restrict-public-access-modifier-in-referenced-library