It would be really neat if we could to native interop with classes.
class NativeMethods{
[DllImport("kernel32", SetLastError=$true)]
hidden static extern [bool] SetConsoleMode([IntPtr] $handle, [int] $mode)
}
How much work would it be to get this working?
Maybe not a lot of work, but it is a common enough ask that we should do it.
There is one important language design choice to make, how to declare a struct. Pinvoke would be much less useful without structs.
A struct is probably not generally useful in PowerShell, we box way too often, so I was thinking of using an attribute like ExplicitLayout to imply struct instead of adding a keyword.
Looks like we may be able to do this as soon as we're clear to move to .NET 3.0 - this already works on 3.0.0-preview2 release of the SDK https://github.com/IISResetMe/PowerShell/commit/4fa5363598e7736771e8cc1b06e8ce8edd405d4f (warrants a bit of a cleanup in PSType.cs, I'll keep working on that in the meantime)
Most helpful comment
Looks like we may be able to do this as soon as we're clear to move to .NET 3.0 - this already works on 3.0.0-preview2 release of the SDK https://github.com/IISResetMe/PowerShell/commit/4fa5363598e7736771e8cc1b06e8ce8edd405d4f (warrants a bit of a cleanup in
PSType.cs, I'll keep working on that in the meantime)