开发者

Silverlight and binding to anonymous types

开发者 https://www.devze.com 2022-12-08 18:48 出处:网络
ScottG开发者_如何学Gou indicated in an admittedly old post that databinding to anonymous types \"just works\"becauseanonymous types are just \"syntactic sugar\" (whatever that means) and from the CLR

ScottG开发者_如何学Gou indicated in an admittedly old post that databinding to anonymous types "just works" because anonymous types are just "syntactic sugar" (whatever that means) and from the CLR perspective they are every bit as real a type as anything I would write up.

However Mike Hillberg posts that such is not the case with silverlight, and in my experience I would agree with him --- however I wish Scott was right, as building these so-called "nominal types" is what I thought anonymous types liberated us from.

Could somebody please explain why, in the case of Silverlight binding to anonymous types doesn't fly.


Mike Hillberg is correct, in Silverlight you cannot bind to anonymous types. A real pity cause it would solve all sorts of problems but there you go.

Binding in Silverlight depends on Reflection and it only supports Reflecting on public types. Since Anonymous types are internal, anonymous types can't be used in binding.

Why can't Silverlight reflect on internal types? Dunno, I'd like to know too.


This question provides a way to bind to anonymous types in Silverlight.

  • Silverlight 4 Data Binding with anonymous types

According to comments it also works in Silverlight 3.


yes, It''s 2014 , I still need to work on SilverNotThatlight , I've been solving the issue using ImpromptuInterface

using ImpromptuInterface;
var value = Impromptu.InvokeGet(owner, propertyInfo.Name);
Impromptu.InvokeSet(target, propertyInfo.Name, value);

Impromptu does way more than this I think its worth it to take the dependency on it

0

精彩评论

暂无评论...
验证码 换一张
取 消