I have a constructor as follows
public class Person : Animal
{
public Person(Settings settings) : base(settings.ActionProperty1)
{
}
}
public class Animal
{
public Animal(Action a)
{
}
}
public class Settings
{
public bool Flag { get; set; }
public Action ActionProperty1 { get; set; }
public Action ActionProperty2 { get; set; }
}
How can I pass the base constructor a different value based on some condition. i.e. Something like the following.
public Person(Settings settings) : base(settings.flag ? settings.ActionProperty1 : settings.ActionProperty2)
{
}
The above gives me a compilation error: CS0173 Type of conditional expression cannot be determined because there is no implicit conversion between 'method group' and 'method group'
Also, i can't resolve this by adding a property setter in the base class. I need to do this in the constructor call to the base
Edit: The answer was provided in the second duplicate linked here. Type of conditional expression cannot be determined (Func) I had to cast one of the optional parameters to an Action. Thank you