Ambiguous types by namespace can not be resolved by using directive
See original GitHub issueHello community,
I am facing an issue when working with using namespace directive in PowerShell. I would like to use the Timezone implementation of Java.Util for a small project and therefore work with IKVM, what is meant to be a .net Implementation of Java providing various assembly files (.dll)
I have the following:
[System.reflection.assembly]::unsafeLoadFrom("IKVM.OpenJDK.Core.dll")
[System.reflection.assembly]::unsafeLoadFrom("IKVM.OpenJDK.Util.dll")
So far so good.
Now I am trying do to this in first line
using namespace Java.Util
Actually I am good here as well, but now I would like to do the following:
([TimeZone]::getAvailableIDs()) | { Write-Host $_}
It won’t let me do since in PowerShell I have an implicit “using System” directive in source code, causing that it will be ambiguous with System.TimeZone
It is no problem whenn calling [Java.Util.Timezone] instead but this makes the using directive being redundant.
Probably my issue is that I can’t do an alias for my namespace. In C# it would be something like using (namespace) JavaTimezone = Java.Util.Timezone
Does similar exist for PowerShell? If not I would like to add it as a feature suggestion.
P.S: In general I am quite unhappy with being the using directive not very well documented. I believe there do also things exist like “using type” and “using assembly”, but there is no documentation about it. Why is that? I’d be glad to use this stuff 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
It would be a breaking change now, but we probably should have not have the implicit
using namespace System
if you have anyusing namespace
statements.We don’t have support for type aliases yet, but the intent was to support
using type TimeZone = Java.Util.TimeZone
- in fact the parser supports this today, but the semantic aspect was never implemented.@lzybkr Thank you very much Jason. I will read carefully.