I have a table which I’m displaying in a grid. I’m being asked to mask the value of certain column if another value in that same row meets some condition.
Take for example:
public class Container
{
public string Name { get; set; }
public int Volume { get; set; }
}
IQueryable<Container> myContainerList;
// Imagine some code to populate the object
Currently, I’m masking the Volume field like so:
var filteredList = from container in myContainerList
let vol = container.Name.ToUpper().Contains("SPECIAL") ?
-1 : container.Volume
select new Container()
{
Name = Name,
Volume = vol
};
This successfully masks the volume of any container with the name “special” in it, but this seems inefficient to me.
Is there a better way of going about this?
I’d add another property to the Container class: