Note that there are some explanatory texts on larger screens.

plurals
  1. POIXamlType interface implementation - weird behavior
    text
    copied!<p>The <strong>IXamlType</strong> interface is defined as follows:</p> <pre><code>[Guid(0x7920eab1, 0xa2e5, 0x479a, 0xbd, 80, 0x6c, 0xef, 60, 11, 0x49, 0x70), Version(0x6020000), WebHostHidden] public interface IXamlType { // Methods object ActivateInstance(); void AddToMap([In] object instance, [In] object key, [In] object value); void AddToVector([In] object instance, [In] object value); object CreateFromString([In] string value); IXamlMember GetMember([In] string name); void RunInitializer(); // Properties IXamlType BaseType { get; } IXamlMember ContentProperty { get; } string FullName { get; } bool IsArray { get; } bool IsBindable { get; } bool IsCollection { get; } bool IsConstructible { get; } bool IsDictionary { get; } bool IsMarkupExtension { get; } IXamlType ItemType { get; } IXamlType KeyType { get; } TypeName UnderlyingType { get; } } </code></pre> <p>When a Metro Application is compiled a <strong>XamlTypeInfo.g.cs</strong> is generated which contains an implementation of this interface as follows:</p> <pre><code>[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks", "4.0.0.0")] [System.Diagnostics.DebuggerNonUserCodeAttribute()] internal class XamlSystemBaseType : IXamlType { string _fullName; Type _underlyingType; public XamlSystemBaseType(string fullName, Type underlyingType) { _fullName = fullName; _underlyingType = underlyingType; } public string FullName { get { return _fullName; } } public Type UnderlyingType { get { return _underlyingType; } } virtual public IXamlType BaseType { get { throw new NotImplementedException(); } } virtual public IXamlMember ContentProperty { get { throw new NotImplementedException(); } } virtual public IXamlMember GetMember(string name) { throw new NotImplementedException(); } virtual public bool IsArray { get { throw new NotImplementedException(); } } virtual public bool IsCollection { get { throw new NotImplementedException(); } } virtual public bool IsConstructible { get { throw new NotImplementedException(); } } virtual public bool IsDictionary { get { throw new NotImplementedException(); } } virtual public bool IsMarkupExtension { get { throw new NotImplementedException(); } } virtual public bool IsBindable { get { throw new NotImplementedException(); } } virtual public IXamlType ItemType { get { throw new NotImplementedException(); } } virtual public IXamlType KeyType { get { throw new NotImplementedException(); } } virtual public object ActivateInstance() { throw new NotImplementedException(); } virtual public void AddToMap(object instance, object key, object item) { throw new NotImplementedException(); } virtual public void AddToVector(object instance, object item) { throw new NotImplementedException(); } virtual public void RunInitializer() { throw new NotImplementedException(); } virtual public object CreateFromString(String input) { throw new NotImplementedException(); } } </code></pre> <hr> <p>The weird thing is that some of the interface implementations are not consistent. If you try to compile this implementation in a stand-alone VS project, it gives the following error as expected:</p> <p><strong>error CS0738: 'ConsoleApplication28.XamlSystemBaseType' does not implement interface member 'ConsoleApplication28.IXamlType.UnderlyingType'. 'ConsoleApplication28.XamlSystemBaseType.UnderlyingType' cannot implement 'ConsoleApplication28.IXamlType.UnderlyingType' because it does not have the matching return type of 'ConsoleApplication28.TypeName'.</strong></p> <hr> <p>My question is how does the .g.cs compile - I confirmed by opening the compiled assembly in Reflector - it also showed the same implementation which has mis-matching signature types for some properties/methods.</p> <p><strong>Update:</strong></p> <p>To confirm what I saw, I used Reflector and saw following:</p> <p>The IXamlType.UnderlyingType (from assembly Windows, Version=255.255.255.255) is defined as:</p> <pre><code>TypeName UnderlyingType { get; } </code></pre> <p>The XamlSystemBaseType found in any Metro app defines UnderlyingType as:</p> <pre><code> public Type UnderlyingType { get; } </code></pre> <p>Given the above, I don't understand how it works!</p> <p><strong>Update #2</strong></p> <p>OK - When you open the Windows.winmd file in Reflector, you see:</p> <pre><code>TypeName UnderlyingType { get; } </code></pre> <p>However, if in Visual Studio you do:</p> <p>Place cursor on <strong>IXamlType</strong> of following line:</p> <p>internal class XamlSystemBaseType : IXamlType</p> <p>Then <strong>Press F12,</strong> the auto-generated definition file that opens has:</p> <pre><code> public Type UnderlyingType { get; } </code></pre> <p>So something is definitely happening under the scenes which I am not aware of! </p> <p>Documentation of what (if??) some types are auto-mapped to other types and rules/attributes corresponding to this would be of much help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload