예제 #1
0
        PropertyEditorControl GetEditor(EditorViewModel vm, NSOutlineView outlineView)
        {
            Type[] genericArgs = null;
            Type   controlType;
            Type   propertyType = vm.GetType();

            if (!ViewModelTypes.TryGetValue(propertyType, out controlType))
            {
                if (propertyType.IsConstructedGenericType)
                {
                    genericArgs  = propertyType.GetGenericArguments();
                    propertyType = propertyType.GetGenericTypeDefinition();
                    ViewModelTypes.TryGetValue(propertyType, out controlType);
                }
            }
            if (controlType == null)
            {
                return(null);
            }

            if (controlType.IsGenericTypeDefinition)
            {
                if (genericArgs == null)
                {
                    genericArgs = propertyType.GetGenericArguments();
                }
                controlType = controlType.MakeGenericType(genericArgs);
            }

            return(SetUpEditor(controlType, vm, outlineView));
        }
예제 #2
0
        protected KitViewModel GetViewModel(string pageName)
        {
            if (!ViewModelTypes.ContainsKey(pageName))
            {
                throw new KeyNotFoundException($@"ViewModel for {pageName} not found");
            }
            KitViewModel viewModel;

            try {
                viewModel = Activator.CreateInstance(ViewModelTypes[pageName]) as KitViewModel;
            }
            catch (Exception e) {
                throw new TypeLoadException($@"Unable create instance for {pageName}ViewModel", e);
            }

            return(viewModel);
        }
예제 #3
0
        public virtual IEditorView GetEditor(IHostResourceProvider hostResources, EditorViewModel vm)
        {
            if (hostResources == null)
            {
                throw new ArgumentNullException(nameof(hostResources));
            }

            Type[] genericArgs = null;
            Type   controlType;
            Type   propertyType = vm.GetType();

            if (!ViewModelTypes.TryGetValue(propertyType, out controlType))
            {
                if (propertyType.IsConstructedGenericType)
                {
                    genericArgs  = propertyType.GetGenericArguments();
                    propertyType = propertyType.GetGenericTypeDefinition();
                    ViewModelTypes.TryGetValue(propertyType, out controlType);
                }
            }

            if (controlType == null)
            {
                return(null);
            }

            if (controlType.IsGenericTypeDefinition)
            {
                if (genericArgs == null)
                {
                    genericArgs = propertyType.GetGenericArguments();
                }

                controlType = controlType.MakeGenericType(genericArgs);
            }

            return((IEditorView)Activator.CreateInstance(controlType, hostResources));
        }
예제 #4
0
 public static Type GetViewModelType(string typeName)
 {
     return(ViewModelTypes.SingleOrDefault(x => x.Name == typeName));
 }