是否有可能一个属性的部分添加类的属性? [英] Is it possible to add an attribute to a property in a partial class?

查看:103
本文介绍了是否有可能一个属性的部分添加类的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不认为这是可能的,但因为我没有从MSDN一个明确清晰,我觉得这是最好的问。假设我们有一个类如下:

I don't think it's possible but since I haven't got a definite clarity from MSDN, I feel that it's best to ask. Suppose that we have a class as follows.

public partial class Hazaa
{
  public int Shazoo { get; set; }
}

然后,我想是的过冷我想在另一个文件中这样做的 Shazoo 的归因。由于我使用部分类,我的添加新的属性如下:

Then, I'd like Shazoo to be attributed as SuperCool but I wish to do so in another file. Since I'm using partial classes, I can add new properties as follows.

public partial class Hazaa
{
  [SuperCool]
  public int Wheee { get; set; }
}

但我可以通过属性在后者写code中的第一个样品中声明的属性?我怀疑这是可能的,但我会很乐意指正。如果是这样,有什么语法?

But can I attribute a property declared in the first sample by writing code in the latter? I doubt it's possible but I'll be glad to stand corrected. If so, what's the syntax?

推荐答案

没有,你不能。

您只能附加属性的成员声明那里,然后,除非该成员还宣布为部分(这样你就可以在其他地方重新实现它),在另一部分文件你不能附加属性成员声明。

You can only attach attributes to members you declare there and then, and unless the member is also declared as partial (so that you may reimplement it elsewhere) you cannot attach attributes to members declared in another partial file.

这篇关于是否有可能一个属性的部分添加类的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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