-3

Some context first. Revit is a software used by architects which has an API you can use to automate some tasks, one of the things you can do is create a dialog which will look like a normal Revit pop up.

This dialog has a CommonButton property that adds default buttons like Yes, No, Cancel and Ok, but I never saw this character | used in this way. What does it mean or do? How is it actually called?

td.CommonButtons = TaskDialogCommonButtons.No | TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.Cancel;

td being your TaskDialog object

This will add Yes, No and Cancel buttons to your dialog.

I already searched for this with no luck, I can only find the "or" logic gate for if statements and doesn't seem to apply to this. Neither did I see it anywhere else than in this Revit context (not that I'm a full time programmer anyway). Thanks

G-BC
  • 101
  • 1
  • 10
  • `"or" ... doesn't seem to apply to this` - why not? – 500 - Internal Server Error May 26 '21 at 15:05
  • 4
    It's called the [logical OR operator](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators#logical-or-operator-) - in this case it'll perform a bitwise OR on the given enum values – Mathias R. Jessen May 26 '21 at 15:05
  • 4
    See [FlagsAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.flagsattribute?view=net-5.0) , which is set on [TaskDialogCommonButtons](https://www.revitapidocs.com/2022/5fa611e4-8569-e756-fc93-a4d3c4d391ec.htm) – Fildor May 26 '21 at 15:07
  • 1
    Note that there are two OR operators in C#. If you apply `|` between two integral values, it evaluates both operands and does a bit-wise OR between the bits that make them up (ex: `5 | 1 == 5` while `5 | 2 == 7`). An interesting side-effect is that if you use `|` between two booleans, you end up with a non-short-circuiting OR. The more familiar `||` OR operator only operates on booleans. It is short-circuiting (if the first operand is evaluated to `true`, the second operand is never evaluated) – Flydog57 May 26 '21 at 15:18

1 Answers1

0

This looks like a bitwise or. This pattern is very common in C. The different TaskDialogCommonButtons options then consist of powers of two, so that ORring them sets different bits in the result.

Ruben
  • 11
  • 1