public void BrowsableAttributeInEnum()
        {
            var enumSource = EnumSourceHelperCore.GetEnumSource(typeof(TestEnum4));

            Assert.AreEqual(1, enumSource.Count());
            Assert.AreEqual(enumSource.FirstOrDefault().Name, TestEnum4.Value2.ToString());
        }
        public void SvgImageExceptionTest()
        {
            var source = EnumSourceHelperCore.GetEnumSource(typeof(EnumWithSvgImage), true, null, false, EnumMembersSortMode.Default,
                                                            (x, y) => { throw new InvalidOperationException(); });

            Assert.AreEqual(GetImageUri(source.ElementAt(0).Image).ToString(), UriPrefix + "icon1.ico");
            Assert.Throws(typeof(ArgumentException), () => { var imageSource = source.ElementAt(1).Image; });
        }
        public void SvgImageTest()
        {
            Func <string, ImageSource> getSvgImageSourceForTest = uri => (ImageSource) new ImageSourceConverter().ConvertFrom(UriPrefix + "icon2.ico");
            var source = EnumSourceHelperCore.GetEnumSource(typeof(EnumWithSvgImage), true, null, false, EnumMembersSortMode.Default,
                                                            (x, y) => { throw new InvalidOperationException(); }, getSvgImageSource: getSvgImageSourceForTest);

            Assert.AreEqual(GetImageUri(source.ElementAt(0).Image).ToString(), UriPrefix + "icon1.ico");
            Assert.AreEqual(GetImageUri(source.ElementAt(1).Image).ToString(), UriPrefix + "icon2.ico");
        }
Beispiel #4
0
        public void ShowImageTest()
        {
            var source = EnumSourceHelperCore.GetEnumSource(typeof(EnumWithIncorrectIconName), true, null, false,
                                                            EnumMembersSortMode.Default, (x, y) => { throw new InvalidOperationException(); }, showImage: false);

            source.Select(x => x.Name).SequenceEqual(new[] { "OneMember", "MemberTwo" }).IsTrue();
            Assert.IsNull(source.ElementAt(0).Image);
            Assert.IsNull(source.ElementAt(1).Image);
        }
 public void OrderedEnumWithSortModeTest()
 {
     EnumSourceHelperCore.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.Default, (x, y) => { throw new InvalidOperationException(); })
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "B", "CCC", "AA", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayName)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "AA", "B", "CCC", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayNameDescending)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "CCC", "B", "AA", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayNameLength)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "B", "AA", "CCC", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayNameLengthDescending)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "CCC", "AA", "B", "XXX", "GGGGGGG" }).IsTrue();
 }
        public void LazyInitTest()
        {
            var source = EnumSourceHelperCore.GetEnumSource(typeof(EnumWithDisplayName), true, null, false, EnumMembersSortMode.Default,
                                                            (x, y) => { throw new InvalidOperationException(); });

            Assert.IsFalse(GetLazyImageSource(source.ElementAt(0)).IsValueCreated);
            var image = new System.Windows.Controls.Image()
            {
                Source = source.ElementAt(0).Image
            };

            Assert.IsTrue(GetLazyImageSource(source.ElementAt(0)).IsValueCreated);
        }
Beispiel #7
0
 void ChangeAssociatedObjectItemsSource()
 {
     if (this.AssociatedObject != null)
     {
         PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.AssociatedObject).Find("ItemsSource", true);
         if (descriptor == null)
         {
             throw new Exception("ItemsSource dependency property required");
         }
         else
         {
             descriptor.SetValue(this.AssociatedObject, EnumSourceHelperCore.GetEnumSource(EnumType, UseNumericEnumValue, NameConverter, SplitNames, SortMode, null, showImage: AllowImages));
         }
     }
 }
 public static IEnumerable <EnumMemberInfo> GetEnumSource(Type enumType, bool useUnderlyingEnumValue = true, IValueConverter nameConverter = null, bool splitNames = false, EnumMembersSortMode sortMode = EnumMembersSortMode.Default)
 {
     return(EnumSourceHelperCore.GetEnumSource(enumType, useUnderlyingEnumValue, nameConverter, splitNames, sortMode, null));
 }
Beispiel #9
0
 public static IEnumerable <EnumMemberInfo> GetEnumSource(Type enumType, bool useUnderlyingEnumValue = true, IValueConverter nameConverter = null, bool splitNames = false,
                                                          EnumMembersSortMode sortMode = EnumMembersSortMode.Default, Func <string, ImageSource> getSvgImageSource = null, Size?imageSize = null)
 {
     return(EnumSourceHelperCore.GetEnumSource(enumType, useUnderlyingEnumValue, nameConverter, splitNames, sortMode, null, getSvgImageSource: getSvgImageSource, imageSize: imageSize));
 }
Beispiel #10
0
 public void ShowImageExceptionTest()
 {
     Assert.Throws <NullReferenceException>(() => EnumSourceHelperCore.GetEnumSource(typeof(EnumWithIncorrectIconName), true, null, false,
                                                                                     EnumMembersSortMode.Default, (x, y) => { throw new InvalidOperationException(); }));
 }