Is this a hole in dynamic binding in C # 4?

I saw a very interesting blog post

public class TableStorageInitializer<TTableEntity> where TTableEntity : class, new()
    {
        public void Initialize()
        {
            InitializeInstance(new TTableEntity());
        }

        public void InitializeInstance(dynamic entity)
        {
            entity.PartitionKey = Guid.NewGuid().ToString();
            entity.RowKey = Guid.NewGuid().ToString();
        }

    }

Note that InitializeInstance takes one parameter, which is of type dynamic. Now, to test this class, I defined another class that is nested in my main program class as follows:

class Program
        {
            static void Main(string[] args)
            {
               TableStorageInitializer<MyClass> x = new TableStorageInitializer<MyClass>();
                x.Initialize();
            }
            private class MyClass
            {
                public string PartitionKey { get; set; }
                public string RowKey { get; set; }
                public DateTime Timestamp { get; set; }
            }
        }

: "MyClass" .

, , Microsoft.CSharp.RuntimeBinder.RuntimeBinderException "entity.PartitionKey = Guide.NewGuid(). ToString()",

, , , : " PartitionKey".
alt text http://img697.imageshack.us/img697/4188/testdl.png

, , . , , , ? , - , - ?

+5
1

- , , "" MyClass, "" PartitionKey.

, # 4. , , - :) , , , , RTM.

, PartitionKey , , - .

"gotchas". :

public int Count(IList list)
{
   int count1 = list.Count; // Fine
   dynamic d = list;
   int count2 = d.Count; // Should work, right?
}

, - , IList.Count , - :

string[] array = new string[10];
Console.WriteLine(array.Count); // Won't compile

, IList, , ...

+5

All Articles