Ejemplo n.º 1
0
        /// <summary>
        /// Updates the content of the control
        /// (after initialization and SelectedObject changes)
        /// </summary>
        private void UpdateContent()
        {
            // Checks if the control has been loaded.
            if
            ((this.IsVisible == false) ||
             (this.InnerGrid == null)
            )
            {
                return;
            }

            // Clear the model.
            this.ClearContent();

            // Try to find view model converter for this given type.
            if (this.EditedObjects != null)
            {
                if (this.EditedObjects.Any())
                {
                    IViewModelConverter lConverter = ConverterViewModelRegistry.Instance.FindBestConverter(this.EditedObjects.First());
                    if (lConverter != null)
                    {
                        List <IPropertyViewModel> lViewModels = lConverter.Convert(this.EditedObjects.First());
                        foreach (var lViewModel in lViewModels)
                        {
                            lViewModel.Instances.Add(this.EditedObjects.First());
                            this.ViewModels.Add(lViewModel);
                        }
                    }
                }
            }
        }
 public void OnResultExecuting(ResultExecutingContext context)
 {
     if (context.Result is ObjectResult objectResult)
     {
         if (objectResult.Value is IEntityModel entityModel)
         {
             objectResult.Value = _viewModelConverter.Convert(entityModel);
         }
         else if (objectResult.Value is IEnumerable <IEntityModel> entityModels)
         {
             objectResult.Value = _viewModelConverter.Convert(entityModels);
         }
         else if (objectResult.Value is IEnumerablePage <IEntityModel> page)
         {
             objectResult.Value = _viewModelConverter.Convert(page);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the type to
        /// </summary>
        /// <param name="pObject">The object to convert.</param>
        /// <returns>The list of retrieved property view model.</returns>
        public List <IPropertyViewModel> Convert(object pObject)
        {
            List <IPropertyViewModel>    lResult     = new List <IPropertyViewModel>();
            PropertyDescriptorCollection lProperties = TypeDescriptor.GetProperties(pObject);

            foreach (var lPropertyInfo in lProperties)
            {
                IViewModelConverter lConverter = ConverterViewModelRegistry.Instance.FindBestConverter(lPropertyInfo);
                if (lConverter != null)
                {
                    lResult.AddRange(lConverter.Convert(lPropertyInfo));
                }
            }
            return(lResult);
        }