From c683567a8c5b2e8f4a1642a360b1c8cc37e99963 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 29 Oct 2017 22:45:40 +0100 Subject: [PATCH] Add BinaryOperatorType.IsBitwise extension. --- ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs | 3 +-- ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index d9ac60f1a..cf81abcc6 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -694,8 +694,7 @@ namespace ICSharpCode.Decompiler.CSharp } } - if ((op == BinaryOperatorType.BitwiseAnd || op == BinaryOperatorType.BitwiseOr || op == BinaryOperatorType.ExclusiveOr) - && (left.Type.Kind == TypeKind.Enum || right.Type.Kind == TypeKind.Enum)) { + if (op.IsBitwise() && (left.Type.Kind == TypeKind.Enum || right.Type.Kind == TypeKind.Enum)) { left = AdjustConstantExpressionToType(left, right.Type); right = AdjustConstantExpressionToType(right, left.Type); } diff --git a/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs b/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs index a1f3bb3d2..4104ac02b 100644 --- a/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs +++ b/ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs @@ -99,5 +99,15 @@ namespace ICSharpCode.Decompiler.CSharp var simpleType = type as SimpleType; return simpleType != null && simpleType.Identifier == "__arglist"; } + + /// + /// Returns true if is bitwise and, bitwise or, or exclusive or. + /// + public static bool IsBitwise(this BinaryOperatorType operatorType) + { + return operatorType == BinaryOperatorType.BitwiseAnd + || operatorType == BinaryOperatorType.BitwiseOr + || operatorType == BinaryOperatorType.ExclusiveOr; + } } }