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

Consider extending .Interface pattern to things other than COM interfaces #279

Open
rickbrew opened this issue Dec 4, 2021 · 2 comments
Labels
proposal An issue that represents a proposed feature or change to the repo. untriaged An issue that has not been triaged by the repo maintainers.

Comments

@rickbrew
Copy link
Contributor

rickbrew commented Dec 4, 2021

For example,

public struct OSVERSIONINFOW : OSVERSIONINFOW.Interface
{
    public interface Interface { ... }
    ...
}

public struct OSVERSIONINFOEXW : OSVERSIONINFOEXW.Interface
{
    public interface Interface : OSVERSIONINFOW.Interface { ... }
    ...
}

This would reify the inheritance relationships, and enable certain uses of generics and would be source-generator friendly (like, I can generate my own __cast() "operator" methods).

Fields, which would have to be exposed as ref properties, might be best left out of the interfaces. Otherwise it would greatly increase friction for implementing and using them (hard to take the address of things).

@rickbrew rickbrew added proposal An issue that represents a proposed feature or change to the repo. untriaged An issue that has not been triaged by the repo maintainers. labels Dec 4, 2021
@rickbrew
Copy link
Contributor Author

rickbrew commented Dec 4, 2021

This might also be useful for the 32 / 64 structs, but it would require some further noodling

[DllImport("shell32", ExactSpelling = true)]
public unsafe static extern BOOL ShellExecuteExW(void* pExecInfo);

public unsafe static extern BOOL ShellExecuteExW<TSHELLEXECUTEINFOW>(TSHELLEXECUTEINFOW* pExecInfo)
    where TSHELLEXECUTEINFOW : unmanaged, SHELLEXECUTEINFOW.Interface
{
    return ShellExecuteExW((void*)pExecInfo);
}

public struct SHELLEXECUTEINFOW : SHELLEXECUTEINFOW.Interface
{
    public interface Interface { }
}

public struct SHELLEXECUTEINFO32W : SHELLEXECUTEINFO32W.Interface
{
    public interface Interface : SHELLEXECUTEINFOW.Interface { }
}

public struct SHELLEXECUTEINFO64W : SHELLEXECUTEINFO64W.Interface
{
    public interface Interface : SHELLEXECUTEINFOW.Interface{ }
}

@rickbrew
Copy link
Contributor Author

rickbrew commented Dec 4, 2021

This idea could potentially go as far as every struct having a .Interface, but I think it's more appropriate to keep it limited to structs which either already have inheritance (e.g. OSVERSIONINFOW and IUnknown), or have multiple forms (e.g. SHELLEXECUTEINFO{32,64}W)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal An issue that represents a proposed feature or change to the repo. untriaged An issue that has not been triaged by the repo maintainers.
Projects
None yet
Development

No branches or pull requests

1 participant