8000 Update CachedReflectionInfo class with parameter types by iSazonov · Pull Request #9029 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Update CachedReflectionInfo class with parameter types#9029

Merged
daxian-dbw merged 23 commits intoPowerShell:masterfrom
iSazonov:add-types-to-signature
Mar 10, 2019
Merged

Update CachedReflectionInfo class with parameter types#9029
daxian-dbw merged 23 commits intoPowerShell:masterfrom
iSazonov:add-types-to-signature

Conversation

@iSazonov
Copy link
Collaborator
@iSazonov iSazonov commented Mar 2, 2019

PR Summary

Related #9016

Use GetMethod overload which allow to specify types of parameters.

PR Context

PR Checklist

@iSazonov iSazonov force-pushed the add-types-to-signature branch 2 times, most recently from e68012f to 817d44d Compare March 2, 2019 21:32
@iSazonov iSazonov force-pushed the add-types-to-signature branch 2 times, most recently from c3eec64 to d995964 Compare March 3, 2019 12:29
@iSazonov iSazonov force-pushed the add-types-to-signature branch from 76e17c9 to 0197507 Compare March 3, 2019 14:31
@iSazonov iSazonov force-pushed the add-types-to-signature branch from f8b76dd to 22472fa Compare March 3, 2019 16:39
@iSazonov iSazonov force-pushed the add-types-to-signature branch from b332436 to 3f910c2 Compare March 3, 2019 17:51
@iSazonov iSazonov added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Mar 3, 2019
@iSazonov iSazonov changed the title WIP: Update CachedReflectionInfo class with parameter types Update CachedReflectionInfo class with parameter types Mar 3, 2019
@daxian-dbw
Copy link
Member

@iSazonov I replied to your comment in the issue #9016 (comment). The update should focus on operations with public members of public types. I don't see a need to do the same for internal types. And furthermore, maybe we can ignore such operations on public interfaces too.

@iSazonov
Copy link
Collaborator Author
iSazonov commented Mar 4, 2019

@daxian-dbw Thanks! I already have done. It was a lot of work.
Seem there is very few public methods. So I leave this at your discretion.

One additional thought. While I was working on it, it turned out that these changes are very sensitive, while the diagnosis is very scanty. If someone changes an internal api, then pwsh can fall with a non-informative error and it will be very difficult to find the cause of the problem. The change doesn't add more information in error message but reduces the likelihood of conflicts and as a result simplify diagnostic.

@daxian-dbw
Copy link
Member
daxian-dbw commented Mar 5, 2019

@iSazonov I appreciate the effort you put behind this PR, thanks!

I'm not too worried about the internal types. Say you are adding an overload to one of the methods used here, then you definitely need to understand what the existing method is used for. Therefore, you will see how it's used in CachedReflectionInfo and gets it updated appropriately as part of your new code.

I'm mainly worried about the .NET public types, because we have no control on changes to them in future version of .NET Core.

@iSazonov
Copy link
Collaborator Author
iSazonov commented Mar 5, 2019

then you definitely need to understand what the existing method is used for.

Yes, but some our namespace is so large that we have the same problem as with public.

So you request is to leave only public (without interfaces)?

Additional: looking how difficult to make signatures for reflection I am thinking about request to enhance .Net Core like:

 static readonly MethodInfo stringIndex =  typeof(System.String).GetMethod("public int IndexOf(char value, StringComparison comparisonType)")
``

iSazonov added 2 commits March 8, 2019 17:39
This reverts commit 8058847.
This reverts commit 0a8f4c0.
iSazonov added 10 commits March 8, 2019 17:39
This reverts commit 3f910c2.
This reverts commit 22472fa.
This reverts commit e7766b1.
This reverts commit 0197507.
This reverts commit 75e7d55.
This reverts commit 53c3a93.
This reverts commit 9893dd4.
This reverts commit b2f7b0e.
This reverts commit 345eb6d.
@iSazonov
Copy link
Collaborator Author
iSazonov commented Mar 8, 2019

@daxian-dbw I found only one public type.

Copy link
Member
@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @iSazonov for making so much effort on this!
Sorry that I didn't make my intention clear enough in the issue, which caused you to spend some effort in vain :(

@daxian-dbw daxian-dbw merged commit ba60904 into PowerShell:master Mar 10, 2019
@iSazonov iSazonov deleted the add-types-to-signature branch March 10, 2019 05:36
@iSazonov
Copy link
Collaborator Author

@daxian-dbw It was a useful mindful exercise. :-) Besides, I learned that refletion is sometimes very confusing.
What do think make sense ask Core team add something like:

 static readonly MethodInfo stringIndex =  typeof(System.String).GetMethod("public int IndexOf(char value, StringComparison comparisonType)")

or

 public delegate int IndexOfDelegate(char value, StringComparison comparisonType)
 static readonly MethodInfo stringIndex =  typeof(System.String).GetMethod(IndexOfDelegate)

@daxian-dbw
Copy link
Member

I don't think they will accept these proposals. The reflection APIs have been there for a long time, and I double they will do any enhancement on them now.

static readonly MethodInfo stringIndex = typeof(System.String).GetMethod("public int IndexOf(char value, StringComparison comparisonType)")

This means the string has to be parsed to the real signature, meaning that the compiler-ish thing needs to kick in ... that's a lot work for not much value.

public delegate int IndexOfDelegate(char value, StringComparison comparisonType)

This means you have to define a delegate for the reflection operation, it's almost same as constructing the type[] you need for the call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0