Some more fixes and refactor#2
Conversation
| { | ||
| var key = (string)enumerator.Key; | ||
| if (predicate(key)) | ||
| foreach (DictionaryEntry entry in _members) |
There was a problem hiding this comment.
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.
When T is PSMemberInfo, returning PSPropertyInfo object is perfectly fine.
| if (delegateOwner == null) | ||
| { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
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.
_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.
These private fields are not necessary. We can just use automatic properties directly.
There was a problem hiding this comment.
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.