In one of my applications I receive a datastruct built like this:
> parent:
> {
> x,
> y,
> z,
> child[]:
> {
> x,
> y
> }
> }
I select the parent object, and then loop through all of the child objects. I use this data to create a 3rd object.
As you can see, some of the properties of the parent object can also be found in the child object. The parent object always has priority, so whenever I loop through the child objects I need to check whether or not I have a value @ the parent level for properties x & y. If I do, then I use the parent's value, if not it's the child's values that are being used.
Originally I created separate methods to these checks for me. I had one for int's, booleans and strings.
In the pull request I was asked to remove those methods and use the ? operator for my comparisons. I personally found my original way of working more readable, but OK.
Now, for the string comparisons I found that the expression to be used was somewhat lengthy:
- var B = parent.X != null ? (!string.IsNullOrEmpty(parent.X.XName) ? parent.X.XName
- : child.X != null ? (!string.IsNullOrEmpty(child.X.XName) ? child.X.XName
- : string.Empty)
- : string.Empty)
- : (child.X != null ? !string.IsNullOrEmpty(child.X.XName) ? child.X.XName
- : string.Empty;
I'm wondering if there are ways to simplify it?