protected virtual IEnumerable <LabelValuePair> GetSourcesSync(ValueProviderArgs args) { if (args.IsNullable) { NullValueLabelAttribute nullLabel = args.PropertyInfo.GetCustomAttribute <NullValueLabelAttribute>(); if (nullLabel == null) { nullLabel = enumType.GetTypeInfo().GetCustomAttribute <NullValueLabelAttribute>(); } if (nullLabel == null) { nullLabel = new NullValueLabelAttribute(); } if (nullLabel.IncludeNullValueLabel) { yield return(new LabelValuePair() { Label = nullLabel.Label, Value = null }); } } foreach (var member in enumType.GetTypeInfo().DeclaredFields.Where(i => i.IsStatic)) //The static decalared fields are our enum values { var label = member.Name; var display = member.GetCustomAttribute <DisplayAttribute>(); if (display != null) { label = display.Name; } yield return(new LabelValuePair() { Label = label, Value = member.Name }); } }
private IEnumerable <ILabelValuePair> GetNullSource(ValueProviderArgs args) { if (args.IsNullable) { //Include the null enum label since we can take null values NullValueLabelAttribute nullLabel = args.PropertyInfo.GetCustomAttribute <NullValueLabelAttribute>(); if (nullLabel == null) { nullLabel = new NullValueLabelAttribute(); } if (nullLabel.IncludeNullValueLabel) { yield return(new LabelValuePair() { Label = nullLabel.Label, Value = null }); } } }