The code below works great. If the Get
and Use
methods are in different assemblies, the code fails with a RuntimeBinderException. This is because the .Net runtime system only guarantees commonality of anonymous types (<string, int>
in this case) within assemblies.
Is there any way to fool the runtime system to overcome this? I can expect the object in the debugger on the Use
side, and the debugger can see the relevant properties.
class Program
{
static void Main(string[] args)
{
UsePerson();
Console.ReadLine();
}
public static void UsePerson()
{
var person = GetPerson();
Console.WriteLine(person.Name);
}
public static dynamic GetPerson()
{
return new { Name = "Foo", Age = 30 };
}
}