C# - Tree / Recursion in Get and Set Accessors?

Instead of just storing the Id of the Parent item, I would store the complete object. That would make this a lot easier (I would also convert those public variables to properties): public class ItemType { public int Id { get; set; } public ItemType Parent { get; set; } public List Children; { get; set; } public double? DefaultDiscount { get; set; } public double?

OverridenDiscount { get; set; } public double CalculatedDiscount { get { return (double)(OverridenDiscount? DefaultDiscount? (Parent!

= null? Parent. CalculatedDiscount : 0)); } } }.

Yeah I literally just figured out that this is the easiest way. Thanks. In related news, I'd like to make it so if someone tries to Set a value to CalculatedDiscount, it leaves CalculatedDiscount intact and just sets OverrideDiscount - can I do this with just OverrideDiscount = value; in the Set accessor?

– Jez Clark Feb 23 at 14:57 @Jez Clark - Yes, that will work although it makes the side-effects of setting CalculatedDiscount difficult to understand. I would leave CalculatedDiscount as a read-only property and for the consumer to set the OverridenDiscount if they need to explicitly set a value. – Justin Niessner Feb 23 at 15:00 I'm using a library (ObjectListView) that needs to bind to a single property, hence the question - I want it to show the calculated value, but when the user edits it, to put the value in the override.

However, after some research I may be able to put that bit of code in the AspectPutter delegate for the OLV, thus leaving the Set accessor alone. Thanks – Jez Clark Feb 23 at 16:17.

I don't see any reason why this is not a good idea. Maybe specify it in Xml comments for that property to make sure others are aware of that behavior but if it represents your program's logic then why not.

Properties are normally considered as not doing much. Because of that, I suggest, you create a method GetCalculatedDiscount that does all the traversing.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions