Can I use an extension method over a list that may be null, and if that is the case then instanciate it just inside the Extension method??
Instanciate the list INSIDE the extension method that applies over it... sounds like when you try to add or remove an item from a list that your are your are iterating with foreach loop.
public static void AddOrUpdate(this List<blabla> i, Person p)
{
i = i ?? new List<blabla>(); //Is it OK no instantiate inside?
i.RemoveAll(t => t.Id == p.Id && t.Role == RoleEnum.Admin);
i.Add(p); //Since it is a reference type, I dont need to return it (even "this" parameter) right?
}
And then use it like this:
//List<blabla> TeamWork comes from anywhere else, instantiated or not
TeamWork.AddOrUpdate(aPersonA);
TeamWork.AddOrUpdate(aPersonB);
DoSomething(Teamwork);