I have the following code:
object foo = ("hello", "world");
var bar = foo as (string, string)?;
if (bar != null) { Console.WriteLine(bar.Value.Item1); }
Edit: I should say that foo
is just an example of a variable I might receive in object
form but should be able to convert.
Resharper highlights the 'as (string, string)' and suggests I Use Pattern Matching
and when I accept, this is the result:
object foo = ("hello", "world");
if (foo is (string, string) bar) { Console.WriteLine(bar.Item1); }
This looks like it should be ok but it does not compile as (string, string)
is highlighted with the error No 'Deconstruct' method with 2 out parameters found for type 'object'
While this code transformation seems like a resharper bug, this is not strictly a resharper-specific question as I'd like to know how should I write this? My original code worked fine but is there a way I can do what my original code is doing with pattern matching?