protected ExtensionCategoryViewModelBase(
            string name,
            ExtensionCategory category,
            IList <IExtension> extenions
            )
        {
            if (extenions == null)
            {
                throw new ArgumentNullException(nameof(extenions));
            }
            if (extenions.Count(x => x != null) == 0)
            {
                throw new ArgumentException("At least one extension is required", nameof(extenions));
            }

            for (int i = 0; i < extenions.Count; i++)
            {
                for (int j = i + 1; j < extenions.Count; j++)
                {
                    if (extenions[i].Name == extenions[j].Name)
                    {
                        throw new ArgumentException($"Extension with name '{extenions[i].Name}' is duplicated", nameof(extenions));
                    }
                }
            }

            Name       = name;
            Category   = category;
            Extensions = extenions
                         .Where(x => x != null)
                         .Select(x => new ExtensionViewModel(this, x))
                         .ToList();
        }
        public MultiSelectionExtensionCategoryViewModel(
            string name,
            ExtensionCategory category,
            IList <IExtension> extenions,
            IEnumerable <string> selectedExtensionNames,
            MultiSelectionExtensionSelectionChangedHandler onSelectionChanged
            ) : base(name, category, extenions)
        {
            this.onSelectionChanged = onSelectionChanged;

            bool hasSelection = false;

            foreach (string extName in selectedExtensionNames.Distinct())
            {
                foreach (ExtensionViewModel ext in Extensions)
                {
                    if (ext.Extension.Name == extName)
                    {
                        ext.IsActive = true;
                        hasSelection = true;
                    }
                }
            }

            if (hasSelection == false)
            {
                Extensions[0].IsActive = true;
            }
        }
        public SingleSelectionExtensionCategoryViewModel(
            string name,
            ExtensionCategory category,
            IList <IExtension> extenions,
            string selectedExtensionName,
            SingleSelectionExtensionSelectionChangedHandler onSelectionChanged
            ) : base(name, category, extenions)
        {
            this.onSelectionChanged = onSelectionChanged;

            bool hasSelection = false;

            foreach (ExtensionViewModel ext in Extensions)
            {
                if (ext.Extension.Name == selectedExtensionName)
                {
                    ext.IsActive = true;
                    hasSelection = true;
                }
            }

            if (hasSelection == false)
            {
                Extensions[0].IsActive = true;
            }
        }
Exemple #4
0
        private ExtensionCategoryViewModelBase GetExtensionCategory(ExtensionCategory category)
        {
            ExtensionCategoryViewModelBase categoryViewModel = Extensions.Categories.FirstOrDefault(x => x.Category == category);

            if (categoryViewModel == null)
            {
                throw new InvalidOperationException($"Extension category '{category}' unavailable");
            }

            return(categoryViewModel);
        }
Exemple #5
0
 private T GetSingleSelectedExtension <T>(ExtensionCategory category)
 {
     return((T)GetSingleSelectedExtension(category).Extension);
 }
Exemple #6
0
        private ExtensionViewModel GetSingleSelectedExtension(ExtensionCategory category)
        {
            ExtensionCategoryViewModelBase categoryViewModel = GetExtensionCategory(category);

            return(GetSingleSelectedExtension(categoryViewModel));
        }
Exemple #7
0
 public List <T> GetFunctionExtensions <T>(ExtensionCategory category)
 {
     throw new NotImplementedException("GetFunctionExtension<T> is not implemented");
 }
Exemple #8
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="ExtensionCategory" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => ExtensionCategory.CreateFrom(sourceValue);