CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Silverlight/Serialization/Customer.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="Customer.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Implementation of a test business object using CSLA managed properties backed by</summary>
7//-----------------------------------------------------------------------
8using System;
9using Csla;
10using Csla.Core;
13
15{
21 [Serializable()]
22 public sealed class Customer : BusinessBase<Customer>, IEquatable<Customer>
23 {
24 #region Constructors
25
26 public Customer()
27 {
30 }
31
32 #endregion
33
34 #region System.Object Method Overrides
35
36 public override bool Equals(object obj)
37 {
38 return Equals(obj as Customer);
39 }
40
41 public override int GetHashCode()
42 {
43 int hashCode = 0;
44
45 if (Name != null) hashCode ^= Name.GetHashCode();
46 if (PrimaryContact != null) hashCode ^= PrimaryContact.GetHashCode();
48
49 return hashCode;
50 }
51
52 #endregion
53
54 #region IEquatable<Customer> Members
55
56 public bool Equals(Customer other)
57 {
58 if (other != null)
59 {
60 return (StringComparer.OrdinalIgnoreCase.Equals(Name, other.Name) &&
63 }
64 else
65 {
66 return false;
67 }
68 }
69
70 #endregion
71
72 #region Custom Serialization Methods
73
74 protected override void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
75 {
76 info.AddChild("PrimaryContact", formatter.SerializeObject(PrimaryContact).ReferenceId);
77 info.AddChild("AccountsPayableContact", formatter.SerializeObject(AccountsPayableContact).ReferenceId);
78 }
79
80 protected override void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
81 {
82 this.PrimaryContact = (CustomerContact)formatter.GetObject(info.Children["PrimaryContact"].ReferenceId);
83 this.AccountsPayableContact = (CustomerContact)formatter.GetObject(info.Children["AccountsPayableContact"].ReferenceId);
84 }
85
86 protected override void OnGetState(SerializationInfo info, StateMode mode)
87 {
88 info.AddValue("Name", Name);
89 }
90
91 protected override void OnSetState(SerializationInfo info, StateMode mode)
92 {
93 this.Name = info.GetValue<string>("Name");
94 }
95
96 #endregion
97
98 #region Properties
99
100 private static PropertyInfo<string> Property_Name = RegisterProperty<string>(c => c.Name, RelationshipTypes.PrivateField);
101 private string _name = Property_Name.DefaultValue;
102
106 public string Name
107 {
108 get { return GetProperty(Property_Name, _name); }
109 set { SetProperty(Property_Name, ref _name, value); }
110 }
111
112 private static PropertyInfo<CustomerContact> Property_PrimaryContact = RegisterProperty<CustomerContact>(c => c.PrimaryContact, "Primary Contact", null, RelationshipTypes.PrivateField);
113 private CustomerContact _primaryContact = Property_PrimaryContact.DefaultValue;
114
119 {
120 get { return GetProperty(Property_PrimaryContact, _primaryContact); }
121 set { SetProperty(Property_PrimaryContact, ref _primaryContact, value); }
122 }
123
124 private static PropertyInfo<CustomerContact> Property_AccountsPayableContact = RegisterProperty<CustomerContact>(c => c.AccountsPayableContact, "A/P Contact", null, RelationshipTypes.PrivateField);
125 private CustomerContact _accountsPayableContact = Property_AccountsPayableContact.DefaultValue;
126
131 {
132 get { return GetProperty(Property_AccountsPayableContact, _accountsPayableContact); }
133 set { SetProperty(Property_AccountsPayableContact, ref _accountsPayableContact, value); }
134 }
135
136 #endregion
137 }
138}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Maintains metadata about a property.
virtual T DefaultValue
Gets the default initial value for the property.
Serializes and deserializes objects at the field level.
IMobileObject GetObject(int referenceId)
Gets a deserialized object based on the object's reference id within the serialization stream.
SerializationInfo SerializeObject(object obj)
Serializes an object into a SerializationInfo object.
Object containing the serialization data for a specific object.
int ReferenceId
Reference number for this object.
Dictionary< string, ChildData > Children
Dictionary containing child reference data.
void AddChild(string name, int referenceId)
Adds a child to the list of child references.
void AddValue(string name, object value)
Adds a value to the serialization stream.
Implementation of a test business object using CSLA managed properties backed by fields,...
Implementation of a test business object using CSLA managed properties backed by fields,...
override void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
override void OnGetState(SerializationInfo info, StateMode mode)
override void OnSetState(SerializationInfo info, StateMode mode)
string Name
Gets or sets the name of the customer.
override void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
CustomerContact PrimaryContact
Gets or sets the primary customer contact.
CustomerContact AccountsPayableContact
Gets or sets the accounts payable contact for the customer.
StateMode
Indicates the reason the MobileFormatter functionality has been invoked.
Definition: StateMode.cs:20
RelationshipTypes
List of valid relationship types between a parent object and another object through a managed propert...
@ Serializable
Prevents updating or inserting until the transaction is complete.