You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "paulirwin (via GitHub)" <gi...@apache.org> on 2024/12/25 23:33:18 UTC

[I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

paulirwin opened a new issue, #1077:
URL: https://github.com/apache/lucenenet/issues/1077

   ### Is there an existing issue for this?
   
   - [X] I have searched the existing issues
   
   ### Task description
   
   Split from PR #1074. There have been a few cases we've fixed where the code has been getting the name of a type as a string by using the pattern `typeof(SomeType).Name`, when code analysis warnings show that we should be using `nameof(SomeType)` instead. This potentially has a small performance benefit if the compiler/PGO is not already smart enough to recognize this pattern, but at the least it will simplify the code and reduce some analysis warnings.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "manognya-b (via GitHub)" <gi...@apache.org>.
manognya-b commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2563862975

   can i take up this issue?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "paulirwin (via GitHub)" <gi...@apache.org>.
paulirwin commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2564383168

   That's correct, and be on the lookout for any other similar opportunities to use `nameof` instead of something off `typeof` (or `.GetType()` for i.e. sealed types that cannot be something else at runtime).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "paulirwin (via GitHub)" <gi...@apache.org>.
paulirwin closed issue #1077: Replace `typeof(X).Name` with `nameof(X)`
URL: https://github.com/apache/lucenenet/issues/1077


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "paulirwin (via GitHub)" <gi...@apache.org>.
paulirwin commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2563903205

   > can i take up this issue?
   
   Please! Keep us posted on your progress, let us know if you have any questions, and submit a PR when ready. Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "paulirwin (via GitHub)" <gi...@apache.org>.
paulirwin commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2576136806

   Fixed by #1091 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "manognya-b (via GitHub)" <gi...@apache.org>.
manognya-b commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2571613195

   Update: I've completed the moving of `typeof(SomeType).Name` to `nameof(SomeType)`. I have been looking into opportunities to convert other similiar usages, and had some queries:
   1. For usages like `x.GetType().NameSpace` and `x.GetType().Fullname`, where the result generated would be different, I was unable to find equivalents like `nameof(x)`. Is there any alternative I can explore for this?
   2. I also wanted some inputs on how to check whether `x.GetType().Name` is sealed or not as manual checking by locating the parent class and looking for the keywords `sealed` or `struct` would be tedious considering the size of the codebase.
   
   Thanks! 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "paulirwin (via GitHub)" <gi...@apache.org>.
paulirwin commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2571682867

   Great! I do not think there is a better option for Namespace and FullName. No worries there.
   
   For `.GetType().Name`, perhaps my idea is not the best. It might make maintenance more difficult in the future if the type of the variable changes in later versions of Lucene. My original thinking was that if `x` was a struct or primitive type like `int`, or `string`, or a sealed class type, then it can't be anything else at runtime, so might as well use `nameof` with the type of `x`. There would not be a need to look at the parent classes, because a parent class by definition can't be sealed. But I hadn't considered the maintenance aspect. Unless you think it's worthwhile to do, I'm good with skipping that for now. 
   
   (Aside: this is where it would be nice if C# had an equivalent of C++'s `decltype` specifier, so we could do `nameof(decltype(x))` to make this a compile-time evaluation, but alas, that's not a thing, yet.)
   
   If you feel good that you've captured all occurrences, I look forward to reviewing your PR when you're ready. Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "paulirwin (via GitHub)" <gi...@apache.org>.
paulirwin commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2564151510

   Using a Regex search might be helpful. I found several hits using this pattern: `typeof\([^\)]*\)\.Name`. There may be other, similar variations of this pattern, though.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Replace `typeof(X).Name` with `nameof(X)` [lucenenet]

Posted by "manognya-b (via GitHub)" <gi...@apache.org>.
manognya-b commented on issue #1077:
URL: https://github.com/apache/lucenenet/issues/1077#issuecomment-2564364810

   > Using a Regex search might be helpful. I found several hits using this pattern: `typeof\([^\)]*\)\.Name`. There may be other, similar variations of this pattern, though.
   
   Thanks for the tip! As I understand it, `typeof(SomeType).Name` has to be moved to `nameof(SomeType)` for all all relevant files in the repository? If this is correct, I will go ahead and use regex to filter out usages and change them appropriately. Thanks! 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org