I want to use an object (returned by framework, not in my control), myField which has a property DisplayFormat of type enum SPNumberFormatTypes.
I want to assign the integer value of DisplayFormat as a string to an XmlAttribute. Here is what I currently do:
myAttribute.Value = ((Int32)((SPNumberFormatTypes)field.DisplayFormat)).ToString();
One more possible way to achieve this is:
myAttribute.Value = ((Int32)Enum.Parse(typeof(SPNumberFormatTypes), field.DisplayFormat.ToString())).ToString();
I want to know if there is a simpler/cleaner way to achieve this?
@itowlson’s comment is the correct answer. Since the enum is already of type SPNumberFormatTypes, there is no need to cast it to that type. Thus my objective can be acheived in an easier way by doing this:
Thanks @itowlson!