我正在阅读关于 <permission>
的 C# 规范使用此语法标记:
<permission cref="member">description</permission>
据说:
This tag allows the security accessibility of a member to be documented where
cref="member"
is the name of a member, whiledescription
is the description of the access to the member.
所以我可以争辩说这样的事情可能是有效的:
/// <permission cref="foo">foo is not accessible</permission>
private void foo() {}
但是在规范中有以下示例:
/// <permission cref="System.Security.PermissionSet">Everyone can
/// access this method.</permission>
public static void Test() { }
如果cref
是必须记录可访问性的成员 什么是 System.Security.PermissionSet
用它做什么?
我真的不明白规范示例!!!
最佳答案
我认为旨在记录给定方法\类的代码访问安全要求。例如:
/// <summary>
/// Do stuff
/// </summary>
/// <permission cref="PermissionSet">Caller should have full trust</permission>
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
public void DoStuff() {
}
这里我们要求完全信任权限集,我们在我们的方法文档中明确说明了这一点。还要考虑这个:
/// <summary>
/// Do stuff 2
/// </summary>
/// <permission cref="FileIOPermission">Caller should have unrestricted IO access</permission>
[FileIOPermission(SecurityAction.Demand, Unrestricted = true)]
public void DoStuff2() {
}
这里我们要求特定的 FileIOPermission
(不是权限集),因此我们在文档中明确声明。
这当然不是为了记录成员的可访问性(公共(public)\私有(private))——为什么要这样做呢?可访问性是函数\类定义的一部分,不需要记录。
关于c# - 在 <permission> 标签上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37211081/