开发者

How can I use an F# type with generics in Silverlight 4 and XAML?

Take the F# following code:

type Blah<'T>(objects : 'T array) as this = // whatever

When I try to use that type in a XAML document, there is no type associated with the generic parameter, and it's ugly. I think the compiler complains, too:

<ns:Blah foo="bar"/>

So, I try to alias the type like so (at the bottom of my Blah.fs file):

type StuffBlah = Blah<Stuff>

Then when I use it in the same way in my XAML document, the type is not found to exist:

<ns:StuffBlah foo="bar"/>

Why is that? Is there a cleaner, more elegant way to do this? I'm still开发者_开发技巧 getting the hang of Silverlight, XAML, and F#, so any advice would be greatly appreciated. Thanks.


The reason the StuffBlah version doesn't work is that particular piece of F# syntax creates a type alias only for the F# project vs. creating an actual type. Since the name is not visible at the IL level as an actual type it is not accessible to Silverlight or XAML in general.

One way to work around this is to create StuffBlah as a first class type which derives from Stuff<'T>. Not ideal at all but it will work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜