public static IEnumerable<EnumMemberInfo> GetEnumSource(Type enumType, bool useUnderlyingEnumValue = true, IValueConverter nameConverter = null, bool splitNames = false, EnumMembersSortMode sortMode = EnumMembersSortMode.Default, Func<string, bool, string> getKnownImageUriCallback = null, bool showImage = true, bool showName = true) { var result = enumType.GetFields(BindingFlags.Static | BindingFlags.Public) .Where(field => DataAnnotationsAttributeHelper.GetAutoGenerateField(field)) .Select(field => { Enum value = (Enum)field.GetValue(null); string name = GetEnumName(field, value, nameConverter, splitNames); var imageInfo = GetImageInfo(MetadataHelper.GetAttribute<ImageAttribute>(field), MetadataHelper.GetAttribute<DXImageAttribute>(field), null, getKnownImageUriCallback); ImageSource image = ViewModelBase.IsInDesignMode ? null : (imageInfo.Item1 ?? imageInfo.Item2).With(x => (ImageSource)new ImageSourceConverter().ConvertFrom(x)); return new EnumMemberInfo(name, DataAnnotationsAttributeHelper.GetFieldDescription(field), useUnderlyingEnumValue ? GetUnderlyingEnumValue(value) : value, image, showImage, showName, DataAnnotationsAttributeHelper.GetFieldOrder(field)); }); switch(sortMode) { case EnumMembersSortMode.DisplayName: result = result.OrderBy(x => x.Name); break; case EnumMembersSortMode.DisplayNameDescending: result = result.OrderByDescending(x => x.Name); break; case EnumMembersSortMode.DisplayNameLength: result = result.OrderBy(x => x.Name.Length); break; case EnumMembersSortMode.DisplayNameLengthDescending: result = result.OrderByDescending(x => x.Name.Length); break; } return result.OrderBy(x => (x.Order != null) ? x.Order : DefaultDisplayOrder).ToArray(); }
public static IEnumerable <EnumMemberInfo> GetEnumSource(Type enumType, bool useUnderlyingEnumValue = true, IValueConverter nameConverter = null, bool splitNames = false, EnumMembersSortMode sortMode = EnumMembersSortMode.Default, Func <string, bool, string> getKnownImageUriCallback = null, bool showImage = true, bool showName = true) { if (enumType == null || !enumType.IsEnum) { return(Enumerable.Empty <EnumMemberInfo>()); } var result = enumType.GetFields(BindingFlags.Static | BindingFlags.Public) .Where(field => DataAnnotationsAttributeHelper.GetAutoGenerateField(field)) .Select(field => { Enum value = (Enum)field.GetValue(null); string name = GetEnumName(field, value, nameConverter, splitNames); var imageInfo = GetImageInfo(MetadataHelper.GetAttribute <ImageAttribute>(field), MetadataHelper.GetAttribute <DXImageAttribute>(field), null, getKnownImageUriCallback); ImageSource image = ViewModelBase.IsInDesignMode || !showImage ? null : (imageInfo.Item1 ?? imageInfo.Item2).With(x => (ImageSource) new ImageSourceConverter().ConvertFrom(x)); return(new EnumMemberInfo(name, DataAnnotationsAttributeHelper.GetFieldDescription(field), useUnderlyingEnumValue ? GetUnderlyingEnumValue(value) : value, image, showImage, showName, DataAnnotationsAttributeHelper.GetFieldOrder(field))); }); switch (sortMode) { case EnumMembersSortMode.DisplayName: result = result.OrderBy(x => x.Name); break; case EnumMembersSortMode.DisplayNameDescending: result = result.OrderByDescending(x => x.Name); break; case EnumMembersSortMode.DisplayNameLength: result = result.OrderBy(x => x.Name.Length); break; case EnumMembersSortMode.DisplayNameLengthDescending: result = result.OrderByDescending(x => x.Name.Length); break; } return(result.OrderBy(x => (x.Order != null) ? x.Order : DefaultDisplayOrder).ToArray()); }
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)); }
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)); }
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); }