-
Notifications
You must be signed in to change notification settings - Fork 0
Some more fixes and refactor #2
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
| { | ||
| var key = (string)enumerator.Key; | ||
| if (predicate(key)) | ||
| foreach (DictionaryEntry entry in _members) |
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.
Here, simply the code using foreach loop.
| private static T AdapterGetFirstMemberOrDefaultDelegate<T>(PSObject msjObj, MemberNamePredicate predicate) where T : PSMemberInfo | ||
| { | ||
| if (msjObj.IsDeserialized && typeof(PSPropertyInfo).IsAssignableFrom(typeof(T))) | ||
| if (msjObj.IsDeserialized && typeof(T).IsAssignableFrom(typeof(PSPropertyInfo))) |
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.
When T is PSMemberInfo, returning PSPropertyInfo object is perfectly fine.
| if (delegateOwner == null) | ||
| { | ||
| 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.
Handle PSObject instance members and PSMemberSet internal members here.
Your original implementation in PSObject.GetFirstPropertyOrDefault handles instance members, but that doesn't cover the PSMemberSet case in this method. So it's probably better to handle both here.
| /// </summary> | ||
| internal PSPropertyInfo GetFirstPropertyOrDefault(MemberNamePredicate predicate) | ||
| { | ||
| if (_instanceMembers != 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.
_instanceMembers could be null because it has been revived yet. It's safer to use the property InstanceMebmers.
This is not needed anymore as the instance members are handled in FirstOrDefault.
| /// <summary> | ||
| /// If this is non-null return this string as the ToString() for this wrapped object. | ||
| /// </summary> | ||
| private string _tokenText; |
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.
These private fields are not necessary. We can just use automatic properties directly.
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 have a PR in the pipeline for extracting those to another ocject. They are rarely used.
PR Summary
Some more fixes and refactoring. Including:
GetFirstOrDefaultXXXDelegatetoGetFirstXXXOrDefaultDelegate.GetFirstOrDefaultinPSMemberInfoCollectiontoFirstOrDefault. It's a collection, so align with theIEnumerable.FirstOrDefault.