CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

static .As<>() method hides instance .As<>() extension method

Open Scottj1s opened this issue 4 years ago • 4 comments

workaround:

using WinRT; ... var obj = ((object)objectWithStaticAs).As<ISomeInstanceInterface();

Scottj1s avatar Oct 12 '20 22:10 Scottj1s

no longer repros

j0shuams avatar Nov 25 '20 17:11 j0shuams

confirmed no repro - must have been a point in time issue with the C# compiler

Scottj1s avatar Nov 25 '20 17:11 Scottj1s

Repro with WinUI3:

public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }

        private void myButton_Click(object sender, RoutedEventArgs e)
        {
            myButton.Content = "Clicked";
            // need to cast to System.Object as a workaround
            var hwnd = ((Object)this).As<Windows.Interop.IWindowNative>().WindowHandle;
        }
    }

angelazhangmsft avatar Apr 30 '21 18:04 angelazhangmsft

Static .As() methods should fall back to calling the extension method for interop interface

Scottj1s avatar Jun 22 '21 23:06 Scottj1s