Skip to content

Instantly share code, notes, and snippets.

@controlflow
Created December 14, 2018 09:38
Show Gist options
  • Save controlflow/8cfde44359b8f585b1b2e9062ad3c498 to your computer and use it in GitHub Desktop.
Save controlflow/8cfde44359b8f585b1b2e9062ad3c498 to your computer and use it in GitHub Desktop.
public RangeKind RangeKind
{
get
{
var hasStartIndex = LeftOperand != null;
var hasEndIndex = RightOperand != null;
if (hasStartIndex)
{
return hasEndIndex ? RangeKind.FromStartToEnd : RangeKind.FromStart;
}
// else
{
return hasEndIndex ? RangeKind.ToEnd : RangeKind.Full;
}
}
}
public RangeKind RangeKind
{
get
{
switch (LeftOperand, RightOperand)
{
case ({ }, { }): return RangeKind.FromStartToEnd;
case ({ }, null): return RangeKind.FromStart;
case (null, { }): return RangeKind.ToEnd;
case (null, null): return RangeKind.Full;
}
}
}
public RangeKind RangeKind
{
get
{
return (LeftOperand, RightOperand) switch
{
({ }, { }) => RangeKind.FromStartToEnd,
({ }, null) => RangeKind.FromStart,
(null, { }) => RangeKind.ToEnd,
(null, null) => RangeKind.Full
};
}
}
@aensidhe
Copy link

aensidhe commented Dec 14, 2018

public RangeKind RangeKind => switch (LeftOperand, RightOperand)
{
    case ({ }, { }): return RangeKind.FromStartToEnd;
    case ({ }, null): return RangeKind.FromStart;
    case (null, { }): return RangeKind.ToEnd;
    case (null, null): return RangeKind.Full;
}

@akarpov89
Copy link

@aensidhe That one is not supported :)
switch (LeftOperand, RightOperand) is a statement, while expression body requires expression. Also semicolon at the end is missing :D
The correct option will be like this:

public RangeKind RangeKind => (LeftOperand, RightOperand) switch
{
    ({ }, { }) => RangeKind.FromStartToEnd,
    ({ }, null) => RangeKind.FromStart,
    (null, { }) => RangeKind.ToEnd,
    (null, null) => RangeKind.Full
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment