123456789101112131415161718192021 |
- using System;
- using System.Collections.Generic;
- namespace JiaZhiQuan.Common.ClassEnum {
- public abstract class AbstractEnum<TEnum> where TEnum : notnull, AbstractEnum<TEnum> {
- protected static readonly Type enumType = typeof(TEnum);
- protected readonly static List<TEnum> Values = ListEnumProperties();
- private static List<TEnum> ListEnumProperties() {
- List<TEnum> values = new List<TEnum>();
- var members = enumType.GetProperties();
- foreach (var item in members) {
- if (item.PropertyType == enumType) {
- TEnum? value = (TEnum?)item.GetValue(enumType);
- if (value != null) { values.Add(value); }
- }
- }
- return values;
- }
- }
- }
|