private static void Validate(BinaryExpression.ExpressionType type) { if (type < BinaryExpression.ExpressionType.Add || type >= BinaryExpression.ExpressionType._Count) { throw new ArgumentException("Invalid ExpressionType value", nameof(type)); } }
public void BinaryExpressionTypeChecks(BinaryExpression.ExpressionType type, bool isBool, bool isComp) { Assert.Equal(isBool, type.IsBooleanType()); Assert.Equal(isComp, type.IsComparisonType()); Assert.Equal(isBool, type.IsBooleanType()); Assert.Equal(isComp, type.IsComparisonType()); }
public static bool IsComparisonType(this BinaryExpression.ExpressionType type) { Validate(type); var idx = (int)type / FlagsPerItem; var offs = (int)type % FlagsPerItem; var flags = (typeflags[idx] >> (offs * BitsPerFlag)) & Flags; if (flags == FlagUnset) { flags = InitFlagsFor(type); } return(flags == FlagComparison); }
private static int InitFlagsFor(BinaryExpression.ExpressionType type) { var field = typeof(BinaryExpression.ExpressionType).GetField(type.ToString(), BindingFlags.Public | BindingFlags.Static); if (field == null) { throw new InvalidOperationException("Could not get field for expression type"); } int flags = FlagNothing; if (field.GetCustomAttribute <BinaryExpression.BooleanAttribute>() != null) { flags = FlagBoolean; } else if (field.GetCustomAttribute <BinaryExpression.ComparisonAttribute>() != null) { flags = FlagComparison; } var idx = (int)type / FlagsPerItem; var offs = (int)type % FlagsPerItem; var bitoffs = offs * BitsPerFlag; int read2; var read = typeflags[idx]; do { read2 = read; read &= ~(Flags << bitoffs); read |= flags << bitoffs; read = Interlocked.CompareExchange(ref typeflags[idx], read, read2); }while (read != read2); return(flags); }