10using System.Linq.Expressions;
11using System.Reflection;
13using System.ComponentModel;
16using System.Collections.Generic;
17using System.Threading.Tasks;
27 INotifyPropertyChanged,
49 if (_fieldManager ==
null)
59 #region Register Properties
79 return Core.FieldManager.PropertyInfoManager.RegisterProperty<P>(objectType, info);
93 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
109 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
125 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
142 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
149 #region Read Properties
166 return Utilities.CoerceValue<P>(typeof(F),
null, ReadProperty<F>(propertyInfo));
179 P result =
default(P);
187 result = (P)data.Value;
206 return MethodCaller.CallPropertyGetter(
this, propertyInfo.
Name);
209 object result =
null;
225 #region Load Properties
246 P oldValue =
default(P);
248 if (fieldData ==
null)
251 fieldData =
FieldManager.LoadFieldData<P>(propertyInfo, oldValue);
259 oldValue = (P)fieldData.Value;
261 LoadPropertyValue<P>(propertyInfo, oldValue, Utilities.CoerceValue<P>(typeof(F), oldValue, newValue),
false);
265 throw new PropertyLoadException(
string.Format(Properties.Resources.PropertyLoadException, propertyInfo.
Name, ex.Message));
291 P oldValue =
default(P);
293 if (fieldData ==
null)
296 fieldData =
FieldManager.LoadFieldData<P>(propertyInfo, oldValue);
304 oldValue = (P)fieldData.Value;
306 LoadPropertyValue<P>(propertyInfo, oldValue, newValue,
false);
310 throw new PropertyLoadException(
string.Format(Properties.Resources.PropertyLoadException, propertyInfo.
Name, ex.Message));
314 private bool LoadPropertyMarkDirty<P>(
PropertyInfo<P> propertyInfo, P newValue)
318 P oldValue =
default(P);
320 if (fieldData ==
null)
323 fieldData =
FieldManager.LoadFieldData<P>(propertyInfo, oldValue);
331 oldValue = (P)fieldData.Value;
333 LoadPropertyValue<P>(propertyInfo, oldValue, newValue,
false);
334 return !oldValue.Equals(newValue);
338 throw new PropertyLoadException(
string.Format(Properties.Resources.PropertyLoadException, propertyInfo.
Name, ex.Message));
342 private void LoadPropertyValue<P>(PropertyInfo<P> propertyInfo, P oldValue, P newValue,
bool markDirty)
344 var valuesDiffer =
false;
345 if (oldValue ==
null)
346 valuesDiffer = newValue !=
null;
348 valuesDiffer = !(oldValue.Equals(newValue));
371 var t = this.GetType();
372 var method = t.GetRuntimeMethods().FirstOrDefault(c => c.Name ==
"LoadProperty" && c.IsGenericMethod);
373 var gm = method.MakeGenericMethod(propertyInfo.
Type);
374 var p =
new object[] { propertyInfo, newValue };
391 var t = this.GetType();
392 var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
393 var method = t.GetMethods(flags).FirstOrDefault(c => c.Name ==
"LoadPropertyMarkDirty" && c.IsGenericMethod);
394 var gm = method.MakeGenericMethod(propertyInfo.
Type);
395 var p =
new object[] { propertyInfo, newValue };
396 return (
bool) gm.Invoke(
this, p);
401 #region INotifyPropertyChanged Members
407 public event PropertyChangedEventHandler PropertyChanged;
415 if (PropertyChanged !=
null)
416 PropertyChanged(
this,
new PropertyChangedEventArgs(propertyName));
421 private PropertyChangedEventHandler _propertyChanged;
423 event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
425 add { _propertyChanged = (PropertyChangedEventHandler)Delegate.Combine(_propertyChanged, value); }
426 remove { _propertyChanged = (PropertyChangedEventHandler)Delegate.Remove(_propertyChanged, value); }
435 if (_propertyChanged !=
null)
436 _propertyChanged(
this,
new PropertyChangedEventArgs(propertyName));
461 if (_fieldManager !=
null)
467 base.OnGetChildren(info, formatter);
478 if (info.
Children.ContainsKey(
"_fieldManager"))
480 int referenceId = info.
Children[
"_fieldManager"].ReferenceId;
484 base.OnSetChildren(info, formatter);
489 #region OnDeserialized
492 [System.Runtime.Serialization.OnDeserialized()]
493 private void OnDeserializedHandler(System.Runtime.Serialization.StreamingContext context)
503 [EditorBrowsable(EditorBrowsableState.Advanced)]
504 protected virtual void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
514 object IManageProperties.GetProperty(
IPropertyInfo propertyInfo) =>
throw new NotImplementedException();
515 object IManageProperties.LazyGetProperty<P>(
PropertyInfo<P> propertyInfo, Func<P> valueGenerator) =>
throw new NotImplementedException();
516 object IManageProperties.LazyGetPropertyAsync<P>(
PropertyInfo<P> propertyInfo, Task<P> factory) =>
throw new NotImplementedException();
519 P IManageProperties.LazyReadProperty<P>(
PropertyInfo<P> propertyInfo, Func<P> valueGenerator) =>
throw new NotImplementedException();
520 P IManageProperties.LazyReadPropertyAsync<P>(
PropertyInfo<P> propertyInfo, Task<P> factory) =>
throw new NotImplementedException();
521 void IManageProperties.SetProperty(
IPropertyInfo propertyInfo,
object newValue) =>
throw new NotImplementedException();
522 void IManageProperties.LoadProperty(
IPropertyInfo propertyInfo,
object newValue) =>
LoadProperty(propertyInfo, newValue);
523 bool IManageProperties.LoadPropertyMarkDirty(
IPropertyInfo propertyInfo,
object newValue) =>
throw new NotImplementedException();
526 bool IManageProperties.HasManagedProperties =>
true;
Provides consistent context information between the client and server DataPortal objects.
Manages properties and property data for a business object.
List< IPropertyInfo > GetRegisteredProperties()
Returns a copy of the property list for the business object.
IFieldData GetFieldData(IPropertyInfo propertyInfo)
Gets the IFieldData object for a specific field.
bool FieldExists(IPropertyInfo propertyInfo)
Returns a value indicating whether an IFieldData entry exists for the specified property.
List< object > GetChildren()
Returns a list of all child objects contained in the list of fields.
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...
ApplicationContext ApplicationContext
Gets the current ApplicationContext.
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.
Implement if a class requires access to the CSLA ApplicationContext type.
ApplicationContext ApplicationContext
Gets or sets the current ApplicationContext object.
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.