1
I’m with a c# application that we’re looking to remove code snippets.
One of the situations I have several If/E-s, where Else doesn’t make sense.
Type like this (as an example):
var entidades= db.Entidades.ToList();
if (!entidades.Where(w => w.ID == 1).Any())
{
db.Entidades.Add(new Entidade{
Id = 1,
Existe = 1,
Descricao = "Descricao"
})
}
else
{
var entidade = entidades.Where(w => w.Id == 1).FirstOrDefault();
entidade.Existe = 1;
entidade.Descricao = "Descricao";
}
And this happens in several parts of the code, many even.
So I would like to make a regular expression that removes all the Else.
If you had created a good abstraction you would avoid this. Read https://answall.com/q/120931/101. I hate Regex so I can’t help you anymore. And there are other problems in how people use LINQ in EF and nobody even notices.
– Maniero
Want to use Regex to remove code? What do you mean? You can give a practical example, even in algorithmic, of how you want to do this?
– João Martins
@Maniero , I think they did not understand what I need, I am not discussing the question of good practices in the code, when I hit my eye I saw that there was redundancy in the code. The point is that I have a class with more than 2000 situations equal to this example, and I wanted to automate to not have all this work.
– Gabriel Santos Reis
@Joãomartins In Visual Studio’s Find and Raplaces tool, in the Replace in Files tab (Shortcut: CTRL + SHIFT + H) you have the option Use Regular Expression, I want to use it to remove all Lses.
– Gabriel Santos Reis
Ha, ok, I was missing the point. Thank you.
– João Martins
And which Pattern you want to identify?
– Leandro Angelo