9using System.Collections.Generic;
11using System.Linq.Expressions;
12using System.Reflection;
16using System.ComponentModel;
28 INotifyPropertyChanged
41 if (_fieldManager ==
null)
49 #region Register Properties
69 return Core.FieldManager.PropertyInfoManager.RegisterProperty<P>(objectType, info);
83 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
99 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
115 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
132 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
139 #region Read Properties
156 return Utilities.CoerceValue<P>(typeof(F),
null, ReadProperty<F>(propertyInfo));
169 P result =
default(P);
177 result = (P)data.Value;
196 return MethodCaller.CallPropertyGetter(
this, propertyInfo.
Name);
199 object result =
null;
215 #region Load Properties
236 P oldValue =
default(P);
238 if (fieldData ==
null)
241 fieldData =
FieldManager.LoadFieldData<P>(propertyInfo, oldValue);
249 oldValue = (P)fieldData.Value;
251 LoadPropertyValue<P>(propertyInfo, oldValue, Utilities.CoerceValue<P>(typeof(F), oldValue, newValue),
false);
255 throw new PropertyLoadException(
string.Format(Properties.Resources.PropertyLoadException, propertyInfo.
Name, ex.Message));
281 P oldValue =
default(P);
283 if (fieldData ==
null)
286 fieldData =
FieldManager.LoadFieldData<P>(propertyInfo, oldValue);
294 oldValue = (P)fieldData.Value;
296 LoadPropertyValue<P>(propertyInfo, oldValue, newValue,
false);
300 throw new PropertyLoadException(
string.Format(Properties.Resources.PropertyLoadException, propertyInfo.
Name, ex.Message));
304 private bool LoadPropertyMarkDirty<P>(
PropertyInfo<P> propertyInfo, P newValue)
308 P oldValue =
default(P);
310 if (fieldData ==
null)
313 fieldData =
FieldManager.LoadFieldData<P>(propertyInfo, oldValue);
321 oldValue = (P)fieldData.Value;
323 LoadPropertyValue<P>(propertyInfo, oldValue, newValue,
false);
324 return !oldValue.Equals(newValue);
328 throw new PropertyLoadException(
string.Format(Properties.Resources.PropertyLoadException, propertyInfo.
Name, ex.Message));
332 private void LoadPropertyValue<P>(PropertyInfo<P> propertyInfo, P oldValue, P newValue,
bool markDirty)
334 var valuesDiffer =
false;
335 if (oldValue ==
null)
336 valuesDiffer = newValue !=
null;
338 valuesDiffer = !(oldValue.Equals(newValue));
361 var t = this.GetType();
362 var method = t.GetRuntimeMethods().FirstOrDefault(c => c.Name ==
"LoadProperty" && c.IsGenericMethod);
363 var gm = method.MakeGenericMethod(propertyInfo.
Type);
364 var p =
new object[] { propertyInfo, newValue };
381 var t = this.GetType();
382 var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
383 var method = t.GetMethods(flags).FirstOrDefault(c => c.Name ==
"LoadPropertyMarkDirty" && c.IsGenericMethod);
384 var gm = method.MakeGenericMethod(propertyInfo.
Type);
385 var p =
new object[] { propertyInfo, newValue };
386 return (
bool) gm.Invoke(
this, p);
391 #region INotifyPropertyChanged Members
397 public event PropertyChangedEventHandler PropertyChanged;
405 if (PropertyChanged !=
null)
406 PropertyChanged(
this,
new PropertyChangedEventArgs(propertyName));
411 private PropertyChangedEventHandler _propertyChanged;
413 event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
415 add { _propertyChanged = (PropertyChangedEventHandler)Delegate.Combine(_propertyChanged, value); }
416 remove { _propertyChanged = (PropertyChangedEventHandler)Delegate.Remove(_propertyChanged, value); }
425 if (_propertyChanged !=
null)
426 _propertyChanged(
this,
new PropertyChangedEventArgs(propertyName));
451 if (_fieldManager !=
null)
457 base.OnGetChildren(info, formatter);
468 if (info.
Children.ContainsKey(
"_fieldManager"))
470 int referenceId = info.
Children[
"_fieldManager"].ReferenceId;
474 base.OnSetChildren(info, formatter);
479 #region OnDeserialized
482 [System.Runtime.Serialization.OnDeserialized()]
483 private void OnDeserializedHandler(System.Runtime.Serialization.StreamingContext context)
493 [EditorBrowsable(EditorBrowsableState.Advanced)]
494 protected virtual void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
Manages properties and property data for a business object.
IFieldData GetFieldData(IPropertyInfo propertyInfo)
Gets the IFieldData object for a specific field.
Base class for an object that is serializable using SerializationFormatterFactory....
virtual bool LoadPropertyMarkDirty(IPropertyInfo propertyInfo, object newValue)
Loads the property vith new value and mark field dirty if value is changed.
virtual void LoadProperty(IPropertyInfo propertyInfo, object newValue)
Loads a property's managed field with the supplied value calling PropertyHasChanged if the value does...
void LoadProperty< P >(PropertyInfo< P > propertyInfo, P newValue)
Loads a property's managed field with the supplied value calling PropertyHasChanged if the value does...
void OnPropertyChanged(IPropertyInfo propertyInfo)
Raises the PropertyChanged event.
virtual void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
This method is called on a newly deserialized object after deserialization is complete.
void LoadPropertyConvert< P, F >(PropertyInfo< P > propertyInfo, F newValue)
Loads a property's managed field with the supplied value calling PropertyHasChanged if the value does...
static PropertyInfo< P > RegisterProperty< P >(Type objectType, PropertyInfo< P > info)
Indicates that the specified property belongs to the type.
virtual object ReadProperty(IPropertyInfo propertyInfo)
Gets a property's value as a specified type.
P ReadProperty< P >(PropertyInfo< P > propertyInfo)
Gets a property's value as a specified type.
void OnPropertyChanged(string propertyName)
Raises the PropertyChanged event.
P ReadPropertyConvert< F, P >(PropertyInfo< F > propertyInfo)
Gets a property's value from the list of managed field values, converting the value to an appropriate...
override void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to manually retrieve child object data from the serializations stream.
FieldDataManager FieldManager
Gets a reference to the field mananger for this object.
static PropertyInfo< P > RegisterProperty< T, P >(Expression< Func< T, object > > propertyLambdaExpression)
Indicates that the specified property belongs to the business object type.
override void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to manually serialize child objects into the serialization stream.
Inherit from this base class to easily create a serializable class.
Maintains metadata about a property.
virtual T DefaultValue
Gets the default initial value for the property.
string Name
Gets the property name value.
Exception indicating a failure to set a property's field.
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.
object Value
Gets or sets the field value.
string Name
Gets the member name value.
Maintains metadata about a property.
RelationshipTypes RelationshipType
Gets the relationship between the declaring object and the object reference in the property.
Type Type
Gets the type of the property.
object DefaultValue
Gets the default initial value for the property.
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.