在C#中,這是不允許的:如何在ObjectScript中使用標誌?
[Flags]
private enum PermissionType
{
Read = 0x0001,
Write = 0x0002,
Execute = 0x0004,
All = Read | Write | Execute
}
這樣:
private bool TestPerm(PermissionType p)
{
if(PermissionType.Read & p) return true; // user can read
if(PermissionType.Write & p) return true; // user can write
if(PermissionType.Execute & p) return true; // user can Execute
//etc
}
可以這樣調用:
Testperm(PermissionType.Read | PermissionType.Write);
我知道有在ObjectScript不枚舉數據類型,但我覺得一個普通類,像這樣的屬性應該工作...
Class Sample.AcknowledgeType Extends %RegisteredObject
{
Property Read As %Integer [ InitialExpression = 1 ];
Property Write As %Integer [ InitialExpression = 2 ];
Property Execute As %Integer [ InitialExpression = 4 ];
Property All As %Integer [ InitialExpression = 7 ];
}
這是我得到的。我如何編寫TestPerm方法?
對於讀InitialExpression應該是1,而不是0 – psr
@psr - 嗯,是的。固定。 –