Am trying to write an API program to check error codes in C#. Am having difficulty using StringEnum.Parse method. I want to
The EntryStatus is a StringEnum, here’s the code for it:
public sealed class EntryStatus : StringEnum
{
public static readonly EntryStatus ERROR_IMPORTING = new EntryStatus("-2");
public static readonly EntryStatus ERROR_CONVERTING = new EntryStatus("-1");
public static readonly EntryStatus IMPORT = new EntryStatus("0");
public static readonly EntryStatus INFECTED = new EntryStatus("virusScan.Infected");
public static readonly EntryStatus SCAN_FAILURE = new EntryStatus("virusScan.ScanFailure");
public static readonly EntryStatus PRECONVERT = new EntryStatus("1");
public static readonly EntryStatus READY = new EntryStatus("2");
public static readonly EntryStatus DELETED = new EntryStatus("3");
public static readonly EntryStatus PENDING = new EntryStatus("4");
public static readonly EntryStatus MODERATE = new EntryStatus("5");
public static readonly EntryStatus BLOCKED = new EntryStatus("6");
public static readonly EntryStatus NO_CONTENT = new EntryStatus("7");
private EntryStatus(string name) : base(name) { }
}
When I print(let’s just start here) an entry status to the console, I get a number:
FilterPager pager = new FilterPager();
List<MediaItem> items = new List<MediaItem>();
//https://forum.kaltura.org/t/c-api-serialize-deserialize-json/10200/3
OnCompletedHandler<ListResponse<MediaEntry>> handler = new OnCompletedHandler<ListResponse<MediaEntry>>(
(ListResponse<MediaEntry> result, Exception e) =>
{
int x = 0;
foreach (MediaEntry MediaEntry in result.Objects)
{
Console.WriteLine(MediaEntry.Status);
}
I get a numeric response, such as 2. How can I print the string of the string Enum?
This is the method I think I need to call
public static StringEnum Parse(Type type, Enums.EntryStatus status, string name)
{
FieldInfo[] fields = type.GetFields();
foreach (FieldInfo field in fields)
{
object val = field.GetValue(null);
if (val.GetType().BaseType == typeof(StringEnum))
{
if (val.ToString() == name)
return (StringEnum)val;
}
}
return null;
}
Problem is I cannot figure out how to call the above Parse method properly
Thank you