所以我創建了一個類像如何重用屬性
public static class SharedDataAnnotations
{
/// <summary>
/// Matches letters, digits, dashes, underscores and spaces.
/// </summary>
public static RegularExpressionAttribute DisplayNameProperCharacters =
new RegularExpressionAttribute(@"^[A-Za-z0-9\-_ ]+$") { ErrorMessage = "Display name can only contain letters, numbers, underscores, dashes and spaces." };
}
,因爲我希望能夠重用
[RegularExpression("@"^[A-Za-z0-9\-_ ]+$"", ErrorMessage = "Display name can only contain letters, numbers, underscores, dashes and spaces.")]
然而,當我試圖把它的屬性一樣
[SharedDataAnnotations.DisplayNameProperCharacters]
我得到錯誤
'SharedDataAnnotations' 不包含一個定義 'DisplayNameProperCharacters'