views:

164

answers:

1

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?

+1  A: 

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 get's 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.

Scott Wisniewski
Wow, that error doesn't make that clear at all! Thanks for letting me know what was going on. I thought I was doing something really bad...
Dan Herbert