/
BitwiseOrBuilder.cs
35 lines (34 loc) · 1.37 KB
/
BitwiseOrBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.ComponentModel;
using System.Linq.Expressions;
using System.Xml.Serialization;
namespace Bonsai.Expressions
{
/// <summary>
/// Represents an expression builder that applies a bitwise OR operation
/// on paired elements of an observable sequence.
/// </summary>
[XmlType("BitwiseOr", Namespace = Constants.XmlNamespace)]
[Description("Applies a bitwise OR operation on paired elements of an observable sequence.")]
public class BitwiseOrBuilder : BinaryOperatorBuilder
{
/// <summary>
/// Returns the expression that applies a bitwise OR operation to the left
/// and right parameters.
/// </summary>
/// <param name="left">The left input parameter.</param>
/// <param name="right">The right input parameter.</param>
/// <returns>
/// The <see cref="Expression"/> that applies a bitwise OR operation to the left
/// and right parameters.
/// </returns>
protected override Expression BuildSelector(Expression left, Expression right)
{
if (left.Type.IsEnum && left.Type == right.Type)
{
left = Expression.Convert(left, left.Type.GetEnumUnderlyingType());
right = Expression.Convert(right, right.Type.GetEnumUnderlyingType());
}
return Expression.Or(left, right);
}
}
}