1

I have this Enum:

public enum SalaryAgreements
{
    [EnumStringValue("ללא")]
    Non,
    [EnumStringValue("הסכם 3")]
    Agree3,
    [EnumStringValue("הסכם 5")]
    Agree5,
}

And I need to get the "EnumStringValue". How can I do that?

I tried toString() and:

SalaryAgreements agreement;         
if ((guider.SalaryAgree != null) || (guider.SalaryAgree == 0))
{
    agreement = (guider.SalaryAgree == 1 ? SalaryAgreements.Agree3 : SalaryAgreements.Agree5);
}
else
{
    agreement = SalaryAgreements.Non;
}
this.salaryAgree = Enum.GetName(agreement.GetType(), agreement);

But i get only the Non, Agree3, Agree5. I need the values like ללא and הסכם.

This is similar to Getting attributes of Enum's value, but they are working with description and I need EnumStringValue. I wasn't able to make their examples to work.

Community
  • 1
  • 1
igor
  • 716
  • 1
  • 9
  • 27
  • public static EnumStringValueAttribute GetConcreteAttribute(Enum enumValue) { FieldInfo fieldInfo = enumValue.GetType().GetField(enumValue.ToString()); if (fieldInfo != null) { object[] attributes = fieldInfo.GetCustomAttributes(typeof(EnumStringValueAttribute), false); if (attributes.Length > 0) { EnumStringValueAttribute attr = attributes[0] as EnumStringValueAttribute; if (attr != null) { return attr; } } } return null; } – igor Sep 14 '14 at 14:30
  • Vote to reopen the question, and then place the code in an Answer block. I think the question was closed due to a misunderstanding, and it was likely because English is not the primary language. – jww Sep 14 '14 at 14:32

0 Answers0