I have a plain object with some boolean property, something like this:
public class Object
{
public bool Prop { get; set; }
}
I want to do something like this:
Object obj;
if(obj != null) { obj.Prop = true; }
but due to stylecop rules I cannot have that if all in one line, I have to split it on multiple lines and this is getting less readable to me. I tried obj?.Prop = true
but it is giving me an The left-hand side of an assignment cannot contain a null propagating operator
error, which I understand. Any other operator I can use? I'm not really expert in c# so I'm not sure which one is the one I should use.
Here is a quick playground to use for testing if you need it: https://ideone.com/LfjKFD