The following variant at least compiles.
public RandomComplexObject RandomProperty
{
get { return _rco; }
set
{
SetProperty(
ref value,
ref _rco,
true,
() => Name,
() => Age.ToString(), //instead of () => Age
() => Weight.ToString());//instead of () => Weight
}
}
The error you're receving, I guess, was in the first place based on the fact that compiler couldn't infer the TProperty
for
protected bool SetProperty<T, TProperty>(
ref T newValue,
ref T currentValue,
bool notify,
params Expression<Func<TProperty>>[] notifications)
{
//...
}
as it's expecting a variable number of arguments of type Expression<Func<TProperty>>
and you passed there lambdas, returning string
, int
and float
. Definitely compiler couldn't determine, which one of them was TProperty
.
In the setter of the Weight
property:
public float Weight
{
get { return _weight; }
set
{
SetProperty(ref value, ref _weight, true, () => Weight, () => Age);
}
}
having Weight
of type float
and Age
of type int
, compiler inferred TProperty
was float
, as there is an implicit conversion from int
to float
.