c# - 在 <permission> 标签上

标签 c# xml-documentation

我正在阅读关于 <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, while description 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/

相关文章:

c# - 命名空间的 XML 文档

asp.net-web-api - 如何使ASP.NET WEB API帮助页面Xml文档注释具有新行

c# - Protobuf.Net 可以序列化动态字典吗?

xml - 我如何引用 <xs :element> into my <xs:documentation>?

c# - 异步等待一系列状态

c# - 如何使用 Swashbuckle 从 WebAPI 上的 Swagger 文档中省略方法

c# - "///<exclude/>"是什么意思?

c# - 在 XML 文档中使用带有 < > 字符的 see cref?

c# - 使用数据集的 Crystal Reports 子报表

c# - 使用 SqlDataReader 执行一系列 SQL 查询