質問

As an example (and the reason of my question), the class Windows.XAML.Media.Transform, as far as I can see from the WinMD info shown by ILDASM, has no defined constructor.

But if I try to derive from that class, on my C# project, compiler complains that non constructor can be found.

This seems to me that this could be a result of hidden visibility of the constructor.

A same effect can be achieved in C# declaring a private (or internal) Constructor, but it must be declared, otherwise a public constructor is created by the compiler, and the class is indeed derivable.

Any hint?

役に立ちましたか?

解決

I think what's going on here is, that the class has explicitly declared an internal (default) constructor, no public constructor(s), so the developers can inherit from the class within the defining assembly. Everybody else, outside the assembly is prevented from beeing able to inherit from the class.

他のヒント

WinRT is an evolution of the COM concepts and is a quite different story as we are talking about binary components and not source inheritance. The most important thing in this ABI story is that the only things of the component that can be used are the ones exposed via interfaces. Constructors cannot be defined in interfaces nor can statics, and this means that WinRT need interfaces for these too.

C# viewes of WinRT components are an artifact of the language projection and not the real layout of the component. To fully understand what's there, you should look at the component in C++, using the native library WRL that is the library used to build the WinRT APIs.

The Constructor is a projection for the factory interface of the WinRT component (and statics, new to WinRT as they didn't exist in COM, have a similar treatment).

When you "new" from C# an object, a Factory component associated to the component is first created. After this the factory create the object. For this reason the constructor question should be seen in terms of factory component and not in terms of constructor (that exist in the underlying implementation but it doesn't really matter as what you see of the component is only its binary contract, the ABI).

So there are different options: 1. A factory does not exist and you cannot create the component. If the Factory interface is internal you can't use it and can't create the object. 2. A factory exists and expose the default constructor. In C# you can new the object 3. A custom factory exists and expose custom constructors (whit parameters).

ITransformFactory is private and I believe this explain the behavior you have seen.

There is much more on this topic as WinRT aggregation is the way they provide binary inheritance and versioning, but this is another (very long) story.

Still digging, and never will stop, that's the fun part of our job :)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top