Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinRT Projected types documentation

There is something called projected types in WinRT. For example, in metadata, the IXamlType.UnderlyingType is defined as:

TypeName UnderlyingType { get; }

However when used in a C# app, it changes as follows:

Type UnderlyingType { get; }

My question is - is there any documentation regarding the rules, API, attributes used for such mappings?

like image 663
logicnp Avatar asked May 21 '12 04:05

logicnp


3 Answers

That's correct, the language projection built into the CLR maps WinRT types to CLR types automatically. Documentation is hard to come by, especially right now when this is still beta material. But there's an excellent white paper available that describes some aspects of the CLR projection. The download is (currently) available here (Note: Word .docx file)

like image 191
Hans Passant Avatar answered Sep 29 '22 04:09

Hans Passant


When windows metadata is created using the low level authoring tools (MIDL with the /winrt switch and MDMERGE), any places in the assembly that would normally use a typedef, the typedef is replaced with typerefs which point inside the same assembly.

That allows the CLR to rewrite the contents of the winmd file replacing the windows runtime type with a corresponding CLR type. The simplest example of this is the Windows.Foundation.Uri type is replaced with System.Uri to C# applications. The CLR knows internally how to map between W.F.Uri and S.Uri and it automatically does this translation for you.

All of this is handled automagically by the system, there are rules for it, but I don't believe that the process is developer controllable - I believe that the type mappings are burned into the CLR implementation.

like image 39
ReinstateMonica Larry Osterman Avatar answered Sep 29 '22 04:09

ReinstateMonica Larry Osterman


This is the link I was talking about which is a video on Channel 9 http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-874T Please note that this is a video of the Build conference which is based on the Developer Preview. I can't predict how much of this info has changed with the Consumer Preview.

I agree that there should be documentation about how this is working. Hopefully they will update the documentation on MSDN soon.

like image 33
ChristiaanV Avatar answered Sep 29 '22 04:09

ChristiaanV