There were a number of discussions around moving method between types. I've got the following idea, please discuss.
Method's 'working set' consists of parameters and type instance (this). Actually, it consists of publically visible static members of types, but this won't change during move, so we ignore this. Local variables stay inplace, so we ignore them too. So, moving method is "changing method enclosing type while maintaining its working set".
1. Temporary forget about access - consider all members publis (for simplicity). After move is complete we can fix access as required or leave it 'red' for user to take care.
2. Convert method to static by introducing explicit parameter 'thisParam' of enclosing type, replace all "this." access (including implicit) into "thisParam." constructs.
Method calls of "instance.Method(param)" are converted to "SourceType.Method(instance, param)".
Now we have static method and can move it to whatever type we need. Remember, all things are temporary public.
3. Move method to designated class. Method calls of "SourceType.Method(instance, param)" are converted to "DestType.Method(instance, param)".
4. If one of the method parameters has destination type, optionally perform reverse action to #2 - convert parameter into implicit "this" and change body accordingly. Calls are converted obviously: "param.Method(instance)"
5. Fix any access issues.
Probably, target type should be limited to types in parameters for instance methods. Or may be not - then #4 is skipped.
What do you think?