BountyHunter has a secure line named JobLine that provides them with Prey to hunt.
The Prey can be changed at any time, either from the JobLine or changing circumstances that make the bounty hunter choose to swap targets.
How can I improve the dependent / calculated property that is being delegated from the BountyHunter to the JobLine ?
using Microsoft.Practices.Prism.ViewModel;
namespace TestBindings
{
public class Prey
{
public Prey()
{
}
}
//Prey Provider
public class JobLine : NotificationObject
{
public JobLine(Prey prey)
{
this.Prey = prey;
}
private Prey _prey;
public Prey Prey
{
get { return _prey; }
set
{
if (_prey != value)
{
_prey = value;
RaisePropertyChanged(nameof(Prey));
}
}
}
}
public class BountyHunter : NotificationObject
{
public BountyHunter(JobLine jobLine)
{
JobLine = jobLine;
}
public Prey Prey
{
get { return JobLine.Prey; }
private set
{
if (JobLine.Prey != value)
{
JobLine.Prey = value;
RaisePropertyChanged(nameof(Prey));
}
}
}
private JobLine _jobLine;
public JobLine JobLine
{
get { return _jobLine; }
private set
{
if (_jobLine != value)
{
_jobLine = value;
RaisePropertyChanged(nameof(JobLine));
RaisePropertyChanged(nameof(Prey));
}
}
}
}
}
1 Answer 1
Is there any reason why you implemented the same logic/property twice? JobLine
already has a property called Prey
:
public Prey Prey { get { return _prey; } set { if (_prey != value) { _prey = value; RaisePropertyChanged(nameof(Prey)); } } }
so why does BountyHunter
have it too if I can access Pray
via JobLine
?
public Prey Prey { get { return JobLine.Prey; } private set { if (JobLine.Prey != value) { JobLine.Prey = value; RaisePropertyChanged(nameof(Prey)); } } }
-
\$\begingroup\$ I think I may have over simplified my question. \$\endgroup\$Ryan Leach– Ryan Leach2017年10月16日 04:19:09 +00:00Commented Oct 16, 2017 at 4:19
-
3\$\begingroup\$ @RyanTheLeach posting simplified code is never a good idea, it always backfires. You should post your real code. \$\endgroup\$t3chb0t– t3chb0t2017年10月16日 04:26:57 +00:00Commented Oct 16, 2017 at 4:26
-
\$\begingroup\$ @RyanTheLeach what t3chb0t said. And now if editing your question would invalidate this answer, please mark it as accepted and post a new question instead - with as much context as possible. MCVE's are for Stack Overflow, not this site. See how to get the best value out of Code Review for more information. \$\endgroup\$Mathieu Guindon– Mathieu Guindon2017年10月16日 13:55:39 +00:00Commented Oct 16, 2017 at 13:55
[ObsoleteAttribute("Please use Prism.Mvvm.BindableBase")]
\$\endgroup\$