Let's have the below class
public void HandleMessage(object message)
{
switch (message)
{
case string bookTitle:
Console.WriteLine($"Received book with title : {bookTitle}");
break;
case int bookId:
Console.WriteLine($"Received book with Id : {bookId}");
break;
//case (long Id,string Title) book:
// Console.WriteLine($"Received book Id : {movie.}");
// break;
case ValueTuple<long, string> book:
Console.WriteLine($"Received book Id : {book.Item1}, {book.Item2}");
break;
default:
Console.WriteLine($"Received unknown book : {message}");
break;
}
}
I'm trying to call HandleMessage method with Named Tuple as below
var bookStore = new BookStore();
bookStore.HandleMessage("Adam & Maro");
bookStore.HandleMessage(9865);
var book = (Id: 13265, Title: "ToThe.Sapce");
bookStore.HandleMessage(book);
Is there any way to allow Named Tuple in switch statement instead of using ValueTuple ?
something like commented code