Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

c# - WinRT reason for disallowing custom generic types or interfaces

After reading about WinRT a bit here and from Build decks, can someone shed light on the specific rationale that lead them to disallow us from passing our own IFoo<T>, yet they do it for their own sanctioned generic interface types?

WinRT must have a mechanism for describing, resolving and passing generic arguments, or some fancy facading around this for their own use.

I can't imagine "flattening" some of my C# class utility libraries in non-generic fashion, which I mainly want to use from C++ and not so much from JS.

I want first-class Intellisense and API support just as much as you do for your own MS types.

So ... why can't we use said mechanism too? Is this likely to be relaxed and allowed later or is this a permanent restriction? Or is this due to the language projection layers themselves custom-handling specific generic types without some WinRT-centralized meta-handling common to any generic type?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Under the covers, the types which are projected as IXxx are implemented by what are called "parameterized interfaces" or "pinterfaces". Each language projection knows how to express the built-in parameterized interfaces in a natural and familiar fashion - for example, the IMap parameterized interface is projected by the CLR as IDictionary.

The language projections (especially JS) don't know what to do with custom parameterized interfaces, so they're not allowed.

There's no way of knowing if this restriction will be relaxed in the future, because there is no way of knowing what features will be added to Windows in the future.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...