Вопрос

Previously I was using object context for my application. So I was using AddToTable() methods like

context.AddToTable(entity);

but now I am using DbContext and I have to use the Add method like

context.Table.Add(entity);

Now I'm having the older method called more than 300 times. So I was wondering is there any solution to change the methods solution wide.

Это было полезно?

Решение

If you want to use you Regex search and replace for this, something along these lines might do the job.

Given that you don't have any other methods named AddToX( you could use the following regex: \.AddTo([^(]+)\(

This would match .AddToX( then you replace with .\1.Add( where \1 is a back-reference, so it might be $1 depending on your flavor of regex.

That would transform .AddToX( into .X.Add(.

How you would process your code with the regex I can't answer so that would only be half the puzzle, many IDE's have project wide search and replace I guess.

Regardless, make backups before you do anything of this nature.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top