Ejemplo n.º 1
0
        /// <inheritdoc />
        public Type Locate(INotifyPropertyChanged viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            Type viewModelType = viewModel.GetType();

#if NETFX_CORE
            Type dialogType = Cache.Get(viewModelType);
#else
            Type?dialogType = Cache.Get(viewModelType);
#endif
            if (dialogType != null)
            {
                return(dialogType);
            }

            string dialogName = GetDialogName(viewModelType);

            dialogType = GetAssemblyFromType(viewModelType).GetType(dialogName);
            if (dialogType == null)
            {
                throw new TypeLoadException(AppendInfoAboutDialogTypeLocators($"Dialog with name '{dialogName}' is missing."));
            }

            Cache.Add(viewModelType, dialogType);

            return(dialogType);
        }
        /// <summary>
        /// Locates the dialog type representing the specified view model in a user interface.
        /// </summary>
        /// <param name="viewModel">The view model to find the dialog type for.</param>
        /// <returns>
        /// The dialog type representing the specified view model in a user interface.
        /// </returns>
        public Type Locate(INotifyPropertyChanged viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            Type viewModelType = viewModel.GetType();

            Type dialogType = Cache.Get(viewModelType);

            if (dialogType != null)
            {
                return(dialogType);
            }

            string dialogName = GetDialogName(viewModelType);

            // Savaged: Added this for Mvvm projects where views follow the naming convention but are in a separate project or dll
            dialogType = GetAssemblyFromType(viewModelType).GetType(dialogName) ?? GetReferencedAssembly().GetType(dialogName);

            if (dialogType == null)
            {
                throw new TypeLoadException(AppendInfoAboutDialogTypeLocators($"Dialog with name '{dialogName}' is missing."));
            }

            Cache.Add(viewModelType, dialogType);

            return(dialogType);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Locates the dialog type representing the specified view model in a user interface.
        /// </summary>
        /// <param name="viewModel">The view model to find the dialog type for.</param>
        /// <returns>
        /// The dialog type representing the specified view model in a user interface.
        /// </returns>
        public Type Locate(INotifyPropertyChanged viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            Type viewModelType = viewModel.GetType();

            Type dialogType = Cache.Get(viewModelType);

            if (dialogType != null)
            {
                return(dialogType);
            }

            string dialogName = GetDialogName(viewModelType);

            dialogType = GetAssemblyFromType(viewModelType).GetType(dialogName);

            // if view name ends with "View"
            if (dialogType == null)
            {
                dialogType = GetAssemblyFromType(viewModelType).GetType(dialogName + "View");
            }

            if (dialogType == null)
            {
                throw new TypeLoadException($"Dialog with name '{dialogName}' is missing.");
            }

            Cache.Add(viewModelType, dialogType);

            return(dialogType);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Locates the dialog type representing the specified view model in a user interface.
        /// </summary>
        /// <param name="viewModel">The view model to find the dialog type for.</param>
        /// <returns>
        /// The dialog type representing the specified view model in a user interface.
        /// </returns>
        internal static Type LocateDialogType(INotifyPropertyChanged viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            Type viewModelType = viewModel.GetType();

            Type dialogType = Cache.Get(viewModelType);

            if (dialogType != null)
            {
                return(dialogType);
            }

            string dialogName         = GetDialogName(viewModelType);
            string dialogAssemblyName = GetAssemblyFullName(viewModelType);

            string dialogFullName = "{0}, {1}".InvariantFormat(
                dialogName,
                dialogAssemblyName);

            dialogType = Type.GetType(dialogFullName);
            if (dialogType == null)
            {
                throw new Exception(Resources.DialogTypeMissing.CurrentFormat(dialogFullName));
            }

            Cache.Add(viewModelType, dialogType);

            return(dialogType);
        }
Ejemplo n.º 5
0
        public void Get()
        {
            // Arrange
            var cache = new DialogTypeLocatorCache();

            cache.Add(typeof(TestDialogViewModel), typeof(TestDialog));

            // Act
            Type?dialogType = cache.Get(typeof(TestDialogViewModel));

            // Assert
            Assert.That(dialogType, Is.EqualTo(typeof(TestDialog)));
        }