alistairv
alistairv
CC#
Created by alistairv on 7/14/2023 in #help
❔ Pattern matching on multiple cases with the same-typed members
and all of those allow for nested member extraction, like Bar1 { InnerBar.Prop1: var p1 } which (at least in my IOp tree use-case) is pretty neat
12 replies
CC#
Created by alistairv on 7/14/2023 in #help
❔ Pattern matching on multiple cases with the same-typed members
similarly to that, in the meantime i thought of
PropType p = bar switch {
Bar1 { Prop1: var p1 } => p1,
Bar2 { Prop2: var p2 } => p2,
_ => null // or throw...
}
if (p != null) // do stuff...
PropType p = bar switch {
Bar1 { Prop1: var p1 } => p1,
Bar2 { Prop2: var p2 } => p2,
_ => null // or throw...
}
if (p != null) // do stuff...
12 replies
CC#
Created by alistairv on 7/14/2023 in #help
❔ Pattern matching on multiple cases with the same-typed members
yes, i just want to capture Prop. and the second code snippet is indeed (in my eyes) elegant and readable <a:thumbs_up:800164030547230730>
12 replies
CC#
Created by alistairv on 7/14/2023 in #help
❔ Pattern matching on multiple cases with the same-typed members
yes^^
12 replies
CC#
Created by alistairv on 7/14/2023 in #help
❔ Pattern matching on multiple cases with the same-typed members
(context: I am iterating an IOp tree in Roslyn and checking the type of the IOperation of the current node I'm in)
12 replies