Sample input:
// remove sensitive data
var user = db.Users.Where(x => x.Id == '123').ToList()
.Omit("PasswordHash", "PasswordSalt", "SecretDataAsInteger");
Output:
{
FirstName: "...",
LastName: "...",
PasswordHash: "", // default value instead of real value
PasswordSalt: "",
SeretDataAsInteger: 0
}
Similar to: https://lodash.com/docs/4.16.4#omit
Preferences:
- I prefer solutions without selecting a new object and setting each property except the ones i want to omit i.e.
var user = ..Users.Select(x => new User {/* here I set each property */})
since this lead to update all reference, in case I have updated the User
model properties later
- Passing object in the omit function instead of properties name as string is also acceptable