static void Main() { object weaklyTyped = CreateCheesecake(); var stronglyTyped = GrottyHacks.Cast(weaklyTyped, new { Fruit = "", Topping = "" }); Console.WriteLine("Cheesecake: {0} ({1})", stronglyTyped.Fruit, stronglyTyped.Topping); }
static void Main() { object weaklyTyped = CreateCheesecake(); //ANONYMOUS TYPE GENERATION var stronglyTyped = GrottyHacks.Cast(weaklyTyped, new { Fruit = "", Topping = "" }); //"MAPPING" Console.WriteLine("Cheesecake: {0} ({1})", stronglyTyped.Fruit, stronglyTyped.Topping); }