Example #1
0
            /// <summary>
            /// Converts the specified object into a instance that implements <see cref="IList"/>.
            /// </summary>
            /// <param name="list"></param>
            /// <returns></returns>
            protected internal override IList ConvertToList(ModelReferenceProperty property, object list)
            {
                if (list == null)
                {
                    return(null);
                }

                if (list is IList)
                {
                    return((IList)list);
                }

                if (list is IListSource)
                {
                    return(((IListSource)list).GetList());
                }

                if (property is ReflectionReferenceProperty)
                {
                    return(null);
                }

                // Add ICollection<T> support

                throw new NotSupportedException("Unable to convert the specified list instance into a valid IList implementation.");
            }
Example #2
0
 public ModelListChangeEvent(ModelInstance instance, ModelReferenceProperty property, IEnumerable <ModelInstance> added, IEnumerable <ModelInstance> removed)
     : base(instance)
 {
     this.Property   = property;
     this.Added      = added.ToArray();
     this.AddedIds   = this.Added.Select(i => i.Id).ToArray();
     this.Removed    = removed.ToArray();
     this.RemovedIds = this.Removed.Select(i => i.Id).ToArray();
 }
Example #3
0
 public ModelListChangeEvent(ModelInstance instance, ModelReferenceProperty property, IEnumerable<ModelInstance> added, IEnumerable<ModelInstance> removed)
     : base(instance)
 {
     this.Property = property;
     this.Added = added.ToArray();
     this.AddedIds = this.Added.Select(i => i.Id).ToArray();
     this.Removed = removed.ToArray();
     this.RemovedIds = this.Removed.Select(i => i.Id).ToArray();
 }
Example #4
0
        internal void Destroy()
        {
            // Remove reference from parent and child instances
            @in.RemoveReference(this);

            // Clear field references
            this.property = null;
            this.@in      = null;
            this.@out     = null;
        }
Example #5
0
        public IModelPropertySource GetSource(ModelInstance root, Func <ModelInstance, ModelReferenceProperty, int, bool> whenNull, Action <ModelInstance, ModelReferenceProperty, int, ModelInstance> whenNotNull)
        {
            // Return the source type for static paths
            if (IsStatic)
            {
                return(ModelContext.Current.GetModelType(SourceType));
            }

            //walk the path performing whenNull if an entity is null
            //if an entity is null and whenNull returns false
            //then exit out of SetValue returning false
            foreach (SourceStep step in this.steps.Take(this.steps.Length - 1))
            {
                ModelReferenceProperty stepProp = (ModelReferenceProperty)step.DeclaringType.Properties[step.Property];
                if (stepProp.IsList)
                {
                    ModelInstanceList list = root.GetList(stepProp);
                    if (list.Count < step.Index + 1 && (whenNull == null || !whenNull(root, stepProp, step.Index)))
                    {
                        return(null);
                    }

                    var item = list[step.Index];

                    if (whenNotNull != null)
                    {
                        whenNotNull(root, stepProp, step.Index, item);
                    }

                    root = item;
                }
                else
                {
                    if (root.GetReference(stepProp) == null && (whenNull == null || !whenNull(root, stepProp, step.Index)))
                    {
                        return(null);
                    }
                    else
                    {
                        //advance to the next step in the chain.
                        var child = root.GetReference(step.Property);

                        if (whenNotNull != null)
                        {
                            whenNotNull(root, stepProp, step.Index, child);
                        }

                        root = child;
                    }
                }
            }

            return(root);
        }
Example #6
0
 /// <summary>
 /// Creates a new <see cref="ModelReference"/> linking two instances through the specified property.
 /// </summary>
 /// <param name="property"></param>
 /// <param name="in"></param>
 /// <param name="out"></param>
 internal ModelReference(ModelReferenceProperty property, ModelInstance @in, ModelInstance @out)
 {
     this.property = property;
     this.@in      = @in;
     this.@out     = @out;
 }
Example #7
0
        /// <summary>
        /// Ensure the destination instance path is valid when nulls are encountered along the path.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="property"></param>
        /// <param name="index"></param>
        bool EnsureDestinationInstance(ModelInstance instance, ModelReferenceProperty property, int index)
        {
            if (property.IsList)
            {
                ModelInstanceList list = instance.GetList(property);
                for (int i = list.Count; i <= index; i++)
                    list.Add(property.PropertyType.Create());
            }
            else
                instance.SetReference(property, property.PropertyType.Create());

            return true;
        }
Example #8
0
 public ListChangeEventAdapter(ModelInstance instance, ModelReferenceProperty property, INotifyCollectionChanged list)
 {
     this.instance = instance;
     this.property = property;
     this.list     = list;
 }
Example #9
0
 protected internal override void OnStopTrackingList(ModelInstance instance, ModelReferenceProperty property, IList list)
 {
     if (list is INotifyCollectionChanged)
     {
         (new ListChangeEventAdapter(instance, property, (INotifyCollectionChanged)list)).Stop();
     }
     else
     {
         base.OnStartTrackingList(instance, property, list);
     }
 }
 protected internal override void OnStopTrackingList(ModelInstance instance, ModelReferenceProperty property, IList list)
 {
     Provider.GetBaseType().OnStopTrackingList(instance, property, list);
 }
 protected internal override IList ConvertToList(ModelReferenceProperty property, object list)
 {
     return(BaseType.ConvertToList(property, list));
 }
Example #12
0
 /// <summary>
 /// Gets the serializable representation of a <see cref="ModelInstance"/>.
 /// </summary>
 /// <param name="property"></param>
 /// <param name="instance"></param>
 /// <returns></returns>
 internal static object GetReference(ModelReferenceProperty property, ModelInstance instance)
 {
     if (instance == null)
         return null;
     else if (instance.Type != property.PropertyType)
         return new { id = instance.Id, type = JsonConverter.GetJsonReferenceType(instance.Type) };
     else
         return instance.Id;
 }
Example #13
0
 protected internal override void OnStopTrackingList(ModelInstance instance, ModelReferenceProperty property, IList list)
 {
     Provider.GetBaseType().OnStopTrackingList(instance, property, list);
 }
Example #14
0
 protected internal override IList ConvertToList(ModelReferenceProperty property, object list)
 {
     return BaseType.ConvertToList(property, list);
 }
Example #15
0
 internal ModelInstanceList(ModelInstance owner, ModelReferenceProperty property)
 {
     this.owner    = owner;
     this.property = property;
 }