为什么属性目标'typevar“无证? [英] Why is the attribute target 'typevar' undocumented?

查看:116
本文介绍了为什么属性目标'typevar“无证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,在C#可以指定的的自定义属性规范,如在实施例

As is well known, in C# one can specify the target of a custom attribute specification, as in the example

[method: SomeDecoration]
[return: SomeOtherMark]
int MyMethod();

里的指标方法:收益帮助指定哪些因素在code中的属性属于

where the "targets" method: and return: help specify what element in the code the attribute belongs to.

根据C#语言规范,下面的属性指标存在:

According to the C# Language Specification, the following attribute targets exist:


  • 全球的:

    • 组装

    • 模块

    • Global ones:
      • assembly
      • module

      • 字段

      • 事件


      • 参数

      • 属性

      • 收益

      • 键入

      • field
      • event
      • method
      • param
      • property
      • return
      • type

      他们中的一些,像字段,是的总是的多余的,因为它始终清楚什么属性坐在没有指定它们。

      Some of them, like field, are always redundant, since it is always clear what the attribute "sits" on without specifying them.

      然而,有确实存在(至少在Visual C#中执行和版本我这里)一个附加属性的目标,即:

      However there does exist (at least in the implementation and version of Visual C# I have here) an additional attribute target, namely:


      • typevar

      • typevar

      这是允许在例如code

      which is allowed for example in the code

      class MyGenericCollection<[typevar: HereYouSee] TItem>    // legal
      {
      }
      

      属性目标 typevar ,就像字段和其他人,永远不会必需的。

      The attribute target typevar, just like field and others, is never required.

      我的问题:的有谁知道为什么 typevar历史原因:未在说明书或文档中提到? 2.0版本的C#语言规范的写入时被这只是忘记了吗?或者,如果它不是一个疏忽,为什么它在所有实施?

      My question: Does anyone know the historic reason why typevar: is not mentioned in the specification or documentation? Was this simply forgotten when the 2.0 version of the C# Language Specification was written? Or if it was not an oversight, why is it implemented at all?

      推荐答案

      其实, typevar 属性目标文档,但似乎只有在规范的C#2.0语言规范:
      http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf#page=399

      Actually, typevar attribute target is documented, but it seems that only in the standardized C# 2.0 Language Specification: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf#page=399

      无论是C#<一个href=\"http://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/CSharp%20Language%20Specification.doc\"相对=nofollow> 3.0 ,也不<一个href=\"http://download.microsoft.com/download/0/B/D/0BDA894F-2CCD-4C2C-B5A7-4EB1171962E5/CSharp%20Language%20Specification.docx\"相对=nofollow> 5.0 语言规范中提到 typevar 。 (我没有发现C#4.0规范。)

      Neither C# 3.0, nor 5.0 Language Specification mentions typevar. (I didn't find C# 4.0 spec.)

      所以回答你的第二个问题,不,它不是遗忘在C#2.0,但此后它遗忘:)我想,这一定是一个疏忽,因为 typevar 属性的目标仍然是(C#5.0)有效。

      So answering your second question, no, it wasn't forgotten in C# 2.0, but it is forgotten since then :) I think this must be an oversight, since the typevar attribute target is still (C# 5.0) valid.

      这篇关于为什么属性目标'typevar“无证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆