Given the following classes:
public class Person
{
public string Name { get; set; }
}
public static class ExtenionPerson
{
public static string GetPersonName(this Person person)
{
return person.Name;
}
}
where a person has a name, and there is an extension method to get the person name. Now if I do:
dynamic person = new Person { Name = "Jon" };
var name = person.GetPersonName();
there will be thrown a RuntimeBinderException.
I know that extension methods should not be invoked on dynamic objects, but why is this now allowed? My guess is that because extension methods are resolved at compile-time and dynamic objects are resolved at runtime, as specified by the intelisense. How right is this?