属性在声明类型上无效

Rob*_*Rob 4 c# sharepoint web-parts sharepoint-2007

我有以下代码,但我收到以下编译错误:

属性"WebPartStorage"在此声明类型上无效.它仅对'property,indexer'声明有效.

属性'FriendlyName'在此声明类型上无效.它仅对'property,indexer'声明有效.

我已经从MSDN文章修改了我的代码:http://msdn.microsoft.com/en-us/library/dd584174(office.11​​).aspx.有没有人知道我做错了导致这个错误?

  [Category("Custom Properties")]
    [DefaultValue(RegionEnum.None)]
    [WebPartStorage(Storage.Shared)]
    [FriendlyName("Region")]
    [Description("Select a value from the dropdown list.")]
    [Browsable(true)]
    protected RegionEnum _Region;
    public RegionEnum Region
    {
        get
        {
            return _Region;
        }
        set
        {
            _Region = value;
        }
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*ell 8

您似乎已将该属性附加到该字段; 属性总是遵循下一个事物(在这种情况下,字段).您应该重新排序,以便它们遵守属性而不是字段.

BTW; 受保护的领域很少是一个好主意(它们应该是私有的); 但特别是如果财产是公开的:有什么意义?

protected RegionEnum _Region;
[Category("Custom Properties")]
[DefaultValue(RegionEnum.None)]
[WebPartStorage(Storage.Shared)]
[FriendlyName("Region")]
[Description("Select a value from the dropdown list.")]
[Browsable(true)]
public RegionEnum Region
{
    get { return _Region; }
    set { _Region = value; }
}
Run Code Online (Sandbox Code Playgroud)