コード例 #1
0
    static void Main()
    {
        object weaklyTyped   = CreateCheesecake();
        var    stronglyTyped = GrottyHacks.Cast(weaklyTyped,
                                                new { Fruit = "", Topping = "" });

        Console.WriteLine("Cheesecake: {0} ({1})",
                          stronglyTyped.Fruit, stronglyTyped.Topping);
    }
コード例 #2
0
    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);
    }