/// <summary>
        /// Convert a property referencing another resource into a <see cref="ResourceReferenceModel"/>
        /// </summary>
        protected ResourceReferenceModel ConvertReference(Resource current, PropertyInfo property)
        {
            // Create reference model from property information and optional attribute
            var referenceModel = new ResourceReferenceModel
            {
                Name = property.Name
            };

            // We can not set current targets if we do not have any
            var value = property.GetValue(current);

            if (value == null)
            {
                return(referenceModel);
            }

            // Convert referenced resource objects and possible instance types
            // TODO Type wrappers in AL5
            var referenceTargets = (value as IEnumerable <IResource>) ?? new[] { (IResource)value };

            foreach (Resource resource in referenceTargets)
            {
                // Load references partially UNLESS they are new, unsaved objects
                var model = ToModel(resource, resource.Id > 0);
                ConvertReferenceRecursion(resource, model);
                referenceModel.Targets.Add(model);
            }

            return(referenceModel);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceReferenceViewModel"/> class.
        /// </summary>
        public ResourceReferenceViewModel(ResourceReferenceModel model, ReferenceTypeViewModel type)
        {
            Model = model;
            CopyFromModel();

            Type = type;
            Targets.CollectionChanged += (sender, args) => NotifyOfPropertyChange(nameof(AnyReference));
        }
 public void UpdateModel(ResourceReferenceModel model, ReferenceTypeViewModel referenceType)
 {
     Model = model;
     Type  = referenceType;
     CopyFromModel();
 }