The Entity Framework has a function with this signature:
public EntityTypeConfiguration<TEntityType> HasKey<TKey>(Expression<Func<TEntityType, TKey>> keyExpression);
If your table has a clustered primary key you can represent that like this:
this.HasKey(t => new { t.Field1, t.Field2 });
My question is, how are they consuming this anonymous type? I would like to build some similar functionality in methods of my own, that allow a lambda expression that returns multiple properties.
Is there some special way to peek into an anonymous type?
They just use reflection.
For additional performance, you can use expression trees to store pre-compiled delegates in a generic type.