I like the idea of โโextending to client classes, which are WCF service data contracts using partial classes. But I ran into a problem that significantly spoils the side.
Imagine that on the server side I have a class:
[DataContract] public class SolidObject { [DataMember] public Point Position { get; set; } [DataMember] public Size Size { get; set; } }
On the client side, I have created a proxy class that is used there at the level of business logic. In accordance with the needs of business logic, I expand it as follows:
public partial class SolidObject { public Rect Bounds { get { return new Rect(Position.X - Size.Width / 2, Position.Y - Size.Height / 2, Size.Width, Size.Height); }} }
Now I want the position or size to change at any time, then the Chounds chage event is fired. The code is easy to execute:
PropertyChanged += (sender, e) => { if ((e.PropertyName == "Position") || (e.PropertyName == "Size")) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Bounds")); };
The question is where is a good place to enter this code.
If the objects were not created by a service call, I would put it in the constructor. But WCF services ignore client-side constructors, see a constructor that does not appear in my WCF client, serialization problem? .
Now, right after the response of the service, my program searches the hierarchy of data contracts, receives the desired objects and adds event handlers. But I do not think this is right.
So, I wonder where this is best done, or maybe reasoning that the whole approach needs to be changed. Any ideas appreciated.