如何限制引用库中的公共访问修饰符? [英] How can I restrict public access modifier in referenced library?
问题描述
我有两个不同的库,它们引用了称为base.dll的基础库。一个库用于Web平台,另一个库用于Windows平台(WPF)。我必须限制在WPF平台中限制一个公共财产,但我想在Web平台中访问它。如何做到这一点?我正在尝试条件编译,但我不知道该怎么做。请帮助我
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;
}
}
参考库1(Web)–引用了基础库,需要访问该库中的CssClass
Referenced Library 1 (Web) – Referenced the base library, need to access CssClass in this library
参考库2:(WPF)-引用了基本库,需要限制此库中的CssClass
Referenced Library 2: (WPF) - Referenced the base library, need to restrict CssClass in this library
推荐答案
这实际上听起来像是设计缺陷。您创建一个库,并定义该库的用户应可访问哪些属性。通常,您不会向特定客户隐藏特定属性。
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.
但是,我认为您可以通过使属性内部
,然后使用 <您的 base.dll
中的code> InternalsVisibleToAttribute :
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;
}
}
这样,除了 InternalsVisibleTo
属性。
这篇关于如何限制引用库中的公共访问修饰符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!