Last active
January 23, 2020 11:34
-
-
Save oleksabor/b1e186be0b80f5e6f64c585535315d8f to your computer and use it in GitHub Desktop.
Revisions
-
oleksabor revised this gist
Jan 23, 2020 . 1 changed file with 24 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,31 @@ public class MyController { public object Get(string id) { return new { Key = id, Value = "val:" + id }; } } class Program { // Application entry-point static void Main() { var sut = new MyController(); // Act. dynamic res = sut.Get("42"); // Second attempt: var a = new { Key = "", Value = "" }; a = Cast(a, res); // <- the code works Console.WriteLine($"{a.Key} {a.Value}"); } private static T Cast<T>(T typeHolder, object x) { // typeHolder above is just for compiler magic // to infer the type to cast x to return (T)x; } } -
oleksabor revised this gist
Jan 23, 2020 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,9 @@ static void Main() // Act. dynamic res = sut.Get("42"); // Second attempt: var a = new { Key = "", Value = "" }; a = Cast(a, res); // <- the code works Console.WriteLine($"{a.Key} {a.Value}"); } -
oleksabor created this gist
Jan 23, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ public class MyController { public object Get(string id) { return new { Key = id, Value = "val:" + id }; } } class Program { // Application entry-point static void Main() { var sut = new MyController(); // Act. dynamic res = sut.Get("42"); // Assert. // Second attempt: var a = new { Key = "", Value = "" }; a = Cast(a, res); // <- the code fails already here Console.WriteLine($"{a.Key} {a.Value}"); } private static T Cast<T>(T typeHolder, object x) { // typeHolder above is just for compiler magic // to infer the type to cast x to return (T)x; }