2012-11-07 22 views
5

C# için bazı VB.net kodu dönüştürmek çalışıyorum "MyEnum.SomeValue değil" için. Ağır kaldırmayı yapmak için SharpDevelop'u kullandım; Ancak oluşturduğu kod, bazı enum manipülasyonunu kırıyor ve bunu manuel olarak nasıl düzelteceğimi bilmiyorum.C# eşdeğer

Orijinal VB.net kodu:

Enum ePlacement 
    Left = 1 
    Right = 2 
    Top = 4 
    Bottom = 8 
    TopLeft = Top Or Left 
    TopRight = Top Or Right 
    BottomLeft = Bottom Or Left 
    BottomRight = Bottom Or Right 
End Enum 

Private mPlacement As ePlacement 

''... 

mPlacement = (mPlacement And Not ePlacement.Left) Or ePlacement.Right 

oluşturulan C# kodu: Resharper enum [Flags] özelliği ilave anlaşılacağı

public enum ePlacement 
{ 
    Left = 1, 
    Right = 2, 
    Top = 4, 
    Bottom = 8, 
    TopLeft = Top | Left, 
    TopRight = Top | Right, 
    BottomLeft = Bottom | Left, 
    BottomRight = Bottom | Right 
} 

private ePlacement mPlacement; 

//... 

//Generates CS0023: Operator '!' cannot be applied to operand of type 'Popup.Popup.ePlacement' 
mPlacement = (mPlacement & !ePlacement.Left) | ePlacement.Right; 

; ancak bunu yapmak hatayı etkilemez. VB Not olarak

+1

bile doğru operatörü ile, yine [Bayraklar] özniteliği olmalıdır. Sharpdevelop'da raporlanan – plinth

+0

hatası: http://community.sharpdevelop.net/forums/p/16388/44685.aspx –

cevap

10

mantıklı ve Bitwise ancak her ikisi kullanılır. C# ! yılında

DEĞİL ve ~ bitsel DEĞİLDİR boolean.

Dolayısıyla, sadece kullanın:

mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right;