-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make PowerShell Core enumerate COM collections #4553
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
Conversation
adityapatwardhan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor comment
|
|
||
| return enumVariant != null ? new ComEnumerator(enumVariant) : null; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add extra line at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a new line.
|
I should use |
|
|
||
| internal static ComEnumerator Create(object comObject) | ||
| { | ||
| if (!comObject.GetType().IsCOMObject) { return null; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check comObject != null ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add a null check here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
| } | ||
| } | ||
|
|
||
| return enumVariant != null ? new ComEnumerator(enumVariant) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use else to exclude duplicate check with line 399?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a duplicate check, line 416 could make enumVariant not null or continue to be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that here slightly hidden logic. Maybe:
// if IEnumVARIANT interface
var enumVariant = comObject as COM.IEnumVARIANT;
if (enumVariant != null)
{
return new ComEnumerator(enumVariant);
}
// if a collection
var enumerable = comObject as IEnumerable;
...
enumVariant = result as COM.IEnumVARIANT;
if (enumVariant != null)
{
return new ComEnumerator(enumVariant);
}
...
return null; // any warnings for users?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more of a coding style rather than an issue that needs to be corrected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I see your point now -- there will be one more null check if the COM object is already an enum variant. Will update the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for understanding and sorry that I was unclear.
| Describe 'Basic COM Tests' -Tags "CI" { | ||
| It "Should enumerate ShellWindows" { | ||
| $shell = New-Object -ComObject "Shell.Application" | ||
| $windows = $shell.Windows() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it work on Core and IoT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. NanoServer and IoT don't have the shell, so these tests don't apply. Will update.
|
@iSazonov I have addressed your comments. Please take another look. Thanks! |
We have new commits - please take another look.
|
@lzybkr @adityapatwardhan We have new commits - please take another look. |
adityapatwardhan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| } | ||
| } | ||
|
|
||
| return enumVariant != null ? new ComEnumerator(enumVariant) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that here slightly hidden logic. Maybe:
// if IEnumVARIANT interface
var enumVariant = comObject as COM.IEnumVARIANT;
if (enumVariant != null)
{
return new ComEnumerator(enumVariant);
}
// if a collection
var enumerable = comObject as IEnumerable;
...
enumVariant = result as COM.IEnumVARIANT;
if (enumVariant != null)
{
return new ComEnumerator(enumVariant);
}
...
return null; // any warnings for users?| } | ||
| catch (Exception) | ||
| { | ||
| /* Catch all exception. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obvious comment and typo (exception -> exceptions). Catch all exceptions - why? Please enhance the comment or remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
@lzybkr Can you approve? |
|
@iSazonov Jason probably doesn't have time to come back and approve it again, so it's up to the maintainer's judgment to see if it's necessary for reviewers who had approved to approve again. There are some guidelines you can use, for example:
Certainly, you will get your own guidelines as you become more experienced in this role. |
|
@daxian-dbw Thank you for the helpful comment! In this case, it's more of a courtesy - I have to show respect and ask him after I formally dismissed his approval. |
|
@iSazonov Another related comment. I usually don't dismiss a reviewer's approval unless the PR needs some fundamental changes (e.g. design flaw, logic changes and etc.). If the following-up changes are touch-ups or minor fixes (like typo, a null condition check, test fix-up), I think it's fine to keep the previous approval, and once the minor issues are addressed, you can approve the PR and merge it. |
|
@daxian-dbw I wonder why CI AppVeyor failed? |
|
I have investigated the failure, it actually a bug in Binder, more specifically at here, the restriction generated in the call to A repro would be: The I cannot open an issue until this PR is merged because the repro requires enumerating a COM collection. |
|
@daxian-dbw Maybe made two commits for code and tests before rebase and merge? |
|
@iSazonov Please just choose 'Squash and merge'. It's a simple fix and there is no need to keep history commits. |
|
A follow-up of the binder bug: |
|
@daxian-dbw Merged. |
|
@iSazonov Thank you for the review and good work as a maintainer 😄 Here are some of my experiences to choose among
As you can see from the main branch history, most of time we use (and prefer to) As for what is a simple/complex/non-trivial fix/work, it's hard to describe but you will have your judgement call as you gain more expeirences. |
|
@daxian-dbw Thanks for sharing your experience! |
Fix #3775
'GetEnumerator()' is not supported on COM collections in .NET Core (see https://github.com/dotnet/corefx/issues/19731), so we need to have our own implementation to enumerate COM collections.