8000 Some more fixes and refactor by daxian-dbw · Pull Request #2 · powercode/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@daxian-dbw
Copy link
@daxian-dbw daxian-dbw commented Mar 13, 2019

PR Summary

Some more fixes and refactoring. Including:

  • Rename the GetFirstOrDefaultXXXDelegate to GetFirstXXXOrDefaultDelegate.
  • Rename the method GetFirstOrDefault in PSMemberInfoCollection to FirstOrDefault. It's a collection, so align with the IEnumerable.FirstOrDefault.
  • Left comments for others.

{
var key = (string)enumerator.Key;
if (predicate(key))
foreach (DictionaryEntry entry in _members)
Copy link
Author

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)))
Copy link
Author

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;
}
Copy link
Author

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)
Copy link
Author

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;
Copy link
Author

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.

Copy link
Owner

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.

@powercode powercode merged commit af563aa into powercode:Perf/Formatting Mar 13, 2019
@daxian-dbw daxian-dbw deleted the myformatting branch March 13, 2019 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0