I have a method called FormattedJoin()
in a utility class called ArrayUtil
. I tried renaming FormattedJoin()
to just Join()
because it's behavior is similar to .NET's string.Join()
so I figured it made sense to use the same name. However, when I try to use Visual Studio to rename the method, I get this warning:
This member may have compiler generated references
with the same name. Refactoring the member will not
update these references, which may introduce semantic
changes and/or build errors into your code.
I can rename the method just fine and it causes no build errors or compiler warnings. Is it safe to do this or should I avoid having a method with this name?
After seeing this error, I opened up Reflector to see if I could find out if .NET had an internal "ArrayUtil.Join()
" or any variation of that and it doesn't look like it. Even if there was an "ArrayUtil.Join()
" method though, wouldn't having a different namespace make this a non-issue?
This has to do with LINQ.
The C# compiler will generate calls to a method named Join when you use the "Join" keyword in a LINQ query. Usually the call gets resolved to one of the LINQ extension methods. If you define your own method with the same signatgure as the LINQ methods, however, the compiler will use yours. The purpose of the warning is to let you know that if you make additional refactoring that the compiler generated method calls will not be modified.
Unless you are trying to write a custom LINQ provider, it's safe to ignore the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With