Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove generated 'As<I>()' methods for static types #1609

Draft
wants to merge 3 commits into
base: staging/AOT
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,12 +1354,12 @@ public unsafe void TestFactoryCast()
IntPtr hstr;

// Access nonstatic class factory
var instanceFactory = Class.As<IStringableInterop>();
var instanceFactory = ActivationFactory.Get("TestComponent.Class").AsInterface<IStringableInterop>();
instanceFactory.ToString(out hstr);
Assert.Equal("Class", MarshalString.FromAbi(hstr));

// Access static class factory
var staticFactory = ComImports.As<IStringableInterop>();
var staticFactory = ActivationFactory.Get("TestComponent.ComImports").AsInterface<IStringableInterop>();
staticFactory.ToString(out hstr);
Assert.Equal("ComImports", MarshalString.FromAbi(hstr));
}
Expand Down
39 changes: 0 additions & 39 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2501,8 +2501,6 @@ Marshal.Release(inner);

void write_attributed_types(writer& w, TypeDef const& type)
{
bool factory_written{};

for (auto&& [interface_name, factory] : get_attributed_types(w, type))
{
if (factory.activatable)
Expand All @@ -2513,43 +2511,6 @@ Marshal.Release(inner);
{
write_composable_constructors(w, factory.type, type, factory.visible ? "public"sv : "protected"sv);
}
else if (factory.statics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably can't stop generating these functions due to back compat. When we generate the Windows SDK projection for instance, the backcompat check there will break.

{
if (!factory_written)
{
factory_written = true;

bool has_base_factory{};
auto extends = type.Extends();
while(!has_base_factory)
{
auto base_semantics = get_type_semantics(extends);
if (std::holds_alternative<object_type>(base_semantics))
{
break;
}
for_typedef(w, base_semantics, [&](auto base_type)
{
for (auto&& [_, base_factory] : get_attributed_types(w, base_type))
{
if (base_factory.statics)
{
has_base_factory = true;
break;
}
}
extends = base_type.Extends();
});
}

w.write(R"(
public static %I As<I>() => ActivationFactory.Get("%.%").AsInterface<I>();
)",
has_base_factory ? "new " : "",
type.TypeNamespace(),
type.TypeName());
}
}
}

write_static_members(w, type);
Expand Down
28 changes: 14 additions & 14 deletions src/cswinrt/strings/ComInteropHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace Windows.ApplicationModel.DataTransfer.DragDrop.Core
#endif
static class DragDropManagerInterop
{
private static IDragDropManagerInterop dragDropManagerInterop = CoreDragDropManager.As<IDragDropManagerInterop>();
private static IDragDropManagerInterop dragDropManagerInterop = ActivationFactory.Get("Windows.ApplicationModel.DataTransfer.DragDrop.Core.CoreDragDropManager").AsInterface<IDragDropManagerInterop>();

public static CoreDragDropManager GetForWindow(IntPtr appWindow)
{
Expand All @@ -160,7 +160,7 @@ namespace Windows.Graphics.Printing
#endif
static class PrintManagerInterop
{
private static IPrintManagerInterop printManagerInterop = PrintManager.As<IPrintManagerInterop>();
private static IPrintManagerInterop printManagerInterop = ActivationFactory.Get("Windows.Graphics.Printing.PrintManager").AsInterface<IPrintManagerInterop>();

public static PrintManager GetForWindow(IntPtr appWindow)
{
Expand Down Expand Up @@ -190,7 +190,7 @@ namespace Windows.Media
#endif
static class SystemMediaTransportControlsInterop
{
private static ISystemMediaTransportControlsInterop systemMediaTransportControlsInterop = SystemMediaTransportControls.As<ISystemMediaTransportControlsInterop>();
private static ISystemMediaTransportControlsInterop systemMediaTransportControlsInterop = ActivationFactory.Get("Windows.Media.SystemMediaTransportControls").AsInterface<ISystemMediaTransportControlsInterop>();

public static SystemMediaTransportControls GetForWindow(IntPtr appWindow)
{
Expand All @@ -214,7 +214,7 @@ namespace Windows.Media.PlayTo
#endif
static class PlayToManagerInterop
{
private static IPlayToManagerInterop playToManagerInterop = PlayToManager.As<IPlayToManagerInterop>();
private static IPlayToManagerInterop playToManagerInterop = ActivationFactory.Get("Windows.Media.PlayTo.PlayToManager").AsInterface<IPlayToManagerInterop>();

public static PlayToManager GetForWindow(IntPtr appWindow)
{
Expand Down Expand Up @@ -243,7 +243,7 @@ namespace Windows.Security.Credentials.UI
#endif
static class UserConsentVerifierInterop
{
private static IUserConsentVerifierInterop userConsentVerifierInterop = UserConsentVerifier.As<IUserConsentVerifierInterop>();
private static IUserConsentVerifierInterop userConsentVerifierInterop = ActivationFactory.Get("Windows.Security.Credentials.UI.UserConsentVerifier").AsInterface<IUserConsentVerifierInterop>();

public static IAsyncOperation<UserConsentVerificationResult> RequestVerificationForWindowAsync(IntPtr appWindow, string message)
{
Expand All @@ -267,7 +267,7 @@ namespace Windows.Security.Authentication.Web.Core
#endif
static class WebAuthenticationCoreManagerInterop
{
private static IWebAuthenticationCoreManagerInterop webAuthenticationCoreManagerInterop = WebAuthenticationCoreManager.As<IWebAuthenticationCoreManagerInterop>();
private static IWebAuthenticationCoreManagerInterop webAuthenticationCoreManagerInterop = ActivationFactory.Get("Windows.Security.Authentication.Web.Core.WebAuthenticationCoreManager").AsInterface<IWebAuthenticationCoreManagerInterop>();

public static IAsyncOperation<WebTokenRequestResult> RequestTokenForWindowAsync(IntPtr appWindow, WebTokenRequest request)
{
Expand Down Expand Up @@ -297,7 +297,7 @@ namespace Windows.UI.ApplicationSettings
#endif
static class AccountsSettingsPaneInterop
{
private static IAccountsSettingsPaneInterop accountsSettingsPaneInterop = AccountsSettingsPane.As<IAccountsSettingsPaneInterop>();
private static IAccountsSettingsPaneInterop accountsSettingsPaneInterop = ActivationFactory.Get("Windows.UI.ApplicationSettings.AccountsSettingsPane").AsInterface<IAccountsSettingsPaneInterop>();

public static AccountsSettingsPane GetForWindow(IntPtr appWindow)
{
Expand Down Expand Up @@ -334,7 +334,7 @@ namespace Windows.UI.Input
static class RadialControllerConfigurationInterop
{
private static IRadialControllerConfigurationInterop radialControllerConfigurationInterop
= RadialControllerConfiguration.As<IRadialControllerConfigurationInterop>();
= ActivationFactory.Get("Windows.UI.Input.RadialControllerConfiguration").AsInterface<IRadialControllerConfigurationInterop>();

public static RadialControllerConfiguration GetForWindow(IntPtr hwnd)
{
Expand All @@ -353,7 +353,7 @@ public static RadialControllerConfiguration GetForWindow(IntPtr hwnd)
#endif
static class RadialControllerInterop
{
private static IRadialControllerInterop radialControllerInterop = RadialController.As<IRadialControllerInterop>();
private static IRadialControllerInterop radialControllerInterop = ActivationFactory.Get("Windows.UI.Input.RadialController").AsInterface<IRadialControllerInterop>();

public static RadialController CreateForWindow(IntPtr hwnd)
{
Expand All @@ -378,7 +378,7 @@ namespace Windows.UI.Input.Core
static class RadialControllerIndependentInputSourceInterop
{
private static IRadialControllerIndependentInputSourceInterop radialControllerIndependentInputSourceInterop
= RadialControllerIndependentInputSource.As<IRadialControllerIndependentInputSourceInterop>();
= ActivationFactory.Get("Windows.UI.Input.Core.RadialControllerIndependentInputSource").AsInterface<IRadialControllerIndependentInputSourceInterop>();

public static RadialControllerIndependentInputSource CreateForWindow(IntPtr hwnd)
{
Expand All @@ -402,7 +402,7 @@ namespace Windows.UI.Input.Spatial
#endif
static class SpatialInteractionManagerInterop
{
private static ISpatialInteractionManagerInterop spatialInteractionManagerInterop = SpatialInteractionManager.As<ISpatialInteractionManagerInterop>();
private static ISpatialInteractionManagerInterop spatialInteractionManagerInterop = ActivationFactory.Get("Windows.UI.Input.Spatial.SpatialInteractionManager").AsInterface<ISpatialInteractionManagerInterop>();

public static SpatialInteractionManager GetForWindow(IntPtr window)
{
Expand All @@ -426,7 +426,7 @@ namespace Windows.UI.ViewManagement
#endif
static class InputPaneInterop
{
private static IInputPaneInterop inputPaneInterop = InputPane.As<IInputPaneInterop>();
private static IInputPaneInterop inputPaneInterop = ActivationFactory.Get("Windows.UI.ViewManagement.InputPane").AsInterface<IInputPaneInterop>();

public static InputPane GetForWindow(IntPtr appWindow)
{
Expand All @@ -445,7 +445,7 @@ public static InputPane GetForWindow(IntPtr appWindow)
#endif
static class UIViewSettingsInterop
{
private static IUIViewSettingsInterop uIViewSettingsInterop = UIViewSettings.As<IUIViewSettingsInterop>();
private static IUIViewSettingsInterop uIViewSettingsInterop = ActivationFactory.Get("Windows.UI.ViewManagement.UIViewSettings").AsInterface<IUIViewSettingsInterop>();

public static UIViewSettings GetForWindow(IntPtr hwnd)
{
Expand All @@ -469,7 +469,7 @@ namespace Windows.Graphics.Display
#endif
static class DisplayInformationInterop
{
private static IDisplayInformationStaticsInterop displayInformationInterop = DisplayInformation.As<IDisplayInformationStaticsInterop>();
private static IDisplayInformationStaticsInterop displayInformationInterop = ActivationFactory.Get("Windows.Graphics.Display.DisplayInformation").AsInterface<IDisplayInformationStaticsInterop>();

public static DisplayInformation GetForWindow(IntPtr window)
{
Expand Down
Loading