1 of 1 people found this helpful
I do not completely understand your objective with the enum usage, but it is relatively easy to convert enums to strings and vice-versa
Enum.ToString Method (): Converts the value of this instance to its equivalent string representation
Enum.Parse Method (Type, String): Converts the string representation of the name or numeric value of enum
Thanks Thyagarajan ,
How would i implement Enum.ToString using my code?
3 of 3 people found this helpful
Let's provide some context to other readers here who may not have been following your posts over the past few weeks regarding writing a data reference. To those who are unfamiliar with it, SaveConfigChanges() is a method used within custom data references. Thus, it helps to let other readers know that your code snippet is defining a custom property inside of a custom data reference.
My advice is that your property signature should be changed from public string TimeRange to public AFSummaryTypes TimeRange. However, by doing so you would need to make a corresponding change in your ConfigString Setter around the code that reads a substring of the ConfigString, and then converts that substring to an AFSummaryTypes. My colleague Thyagarajan Ramachandran has already given you a great link towards that end. Grabbing a relevant section of code from another of your posts:
I would change your original code here:
case "timerangemethod": AFSummaryTypes summaryType; Enum.TryParse(keyValue, true, out summaryType); if (Enum.IsDefined(typeof(AFSummaryTypes), summaryType) | summaryType.ToString().Contains(",")) _timeRangeMethod = summaryType; else _timeRangeMethod = AFSummaryTypes.None; break;
case "timerangemethod": if (!Enum.TryParse(keyValue, true, out _timeRangeMethod)) _timeRangeMethod = AFSummaryTypes.None; break;
What I would most like to convey to you is that it is your duty as the developer of this custom data reference to take extreme care of composing the ConfigString based on associated properties (as determined by YOU), as well decomposing the ConfigString into those associated properties. The recommendation is that such properties should be typed accordingly (e.g. AFSummaryTypes rather than string).