Exemple #1
0
 protected ModelProperty(string name, Type type, Type declaringType)
 {
     this.Name = name;
     this.Type = type;
     this.DeclaringType = declaringType;
     this.opposite = null;
 }
Exemple #2
0
 void INotifyModelClass.OnAddValue(ModelProperty property, object value, bool firstCall)
 {
     bool added = false;
     if (property.IsCollection)
     {
         IModelCollection collection = this.GetValue(property) as IModelCollection;
         if (collection != null)
         {
             if (value != null && collection.Add(value))
             {
                 added = true;
             }
             else if (value != null && firstCall)
             {
                 added = true;
             }
         }
     }
     else
     {
         object oldValue = this.GetValue(property);
         if (value != oldValue)
         {
             if (oldValue != null)
             {
                 (this as INotifyModelClass).OnRemoveValue(property, oldValue, false);
             }
             this.values[property] = value;
             added = value != null;
         }
         else
         {
             added = value != null && firstCall;
         }
     }
     if (added)
     {
         ModelProperty oppositeProperty = property.Opposite;
         if (oppositeProperty != null)
         {
             INotifyModelClass oppositeObject = value as INotifyModelClass;
             if (oppositeObject != null)
             {
                 oppositeObject.OnAddValue(oppositeProperty, this, false);
             }
         }
     }
 }
Exemple #3
0
 public object GetValue(ModelProperty property)
 {
     object value;
     if (this.values.TryGetValue(property, out value))
     {
         return value;
     }
     else
     {
         Func<object> initializer;
         if (this.initializers.TryGetValue(property, out initializer))
         {
             value = initializer();
             this.values[property] = value;
             if (!property.IsCollection)
             {
                 (this as INotifyModelClass).OnAddValue(property, value, true);
             }
             return value;
         }
     }
     return null;
 }
Exemple #4
0
 public static void LazyInit(ModelClass obj, ModelProperty property, Func<object> value)
 {
     obj.initializers.Add(property, value);
 }
Exemple #5
0
 public void SetValue(ModelProperty property, object newValue)
 {
     object oldValue;
     if (this.values.TryGetValue(property, out oldValue))
     {
         if (newValue == oldValue) return;
     }
     if (property.IsCollection)
     {
         this.values[property] = newValue;
     }
     else
     {
         (this as INotifyModelClass).OnAddValue(property, newValue, true);
     }
 }
Exemple #6
0
 public void LazyInit(ModelProperty property, Func<object> value)
 {
     this.initializers.Add(property, value);
 }
Exemple #7
0
 public ModelCollectionBase(IModelClass owner, ModelProperty ownerProperty)
 {
     this.Owner = owner;
     this.OwnerProperty = ownerProperty;
 }
Exemple #8
0
 protected static ModelProperty RegisterProperty(Type declaringType, string name, ModelProperty property)
 {
     Dictionary<string, ModelProperty> propertyList;
     if (!ModelProperty.properties.TryGetValue(declaringType, out propertyList))
     {
         propertyList = new Dictionary<string, ModelProperty>();
         ModelProperty.properties.Add(declaringType, propertyList);
     }
     propertyList.Add(name, property);
     return property;
 }