C# Entry Status

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>();
            OnCompletedHandler<ListResponse<MediaEntry>> handler = new OnCompletedHandler<ListResponse<MediaEntry>>(
                      (ListResponse<MediaEntry> result, Exception e) =>
                          int x = 0;
                          foreach (MediaEntry MediaEntry in result.Objects)

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

I’ve struggled with this myself and I never figured it out. I eventually gave up. If you ever find a solution, please post it here. You would think MediaEntry.Status.ToString() would do it, but that would only work if EntryStatus was a native enum type and it is not. The ToString() method returns what I would consider to be the numeric “value”, but they call it “name” which makes it very confusing. As far as I can tell, the Kaltura C# API library rolls there own “enum” as a StringEnum class rather than the C# enum type. Maybe this is how it’s done in other languages? The Parse method you refer to is used to create the StringEnum from a string input, with that string actually being the number, so that won’t help you. Maybe the Kaltura developers could chime in here.

Thanks for the reply @dhess1

I will definitely let you know if I ever find out how to properly parse/read/manipulate EntryStatus objects. I’ve tried on Stackoverflow, no good answer.

The custom StringEnum class has some unusual behavior I would like to understand better. Your answer has helped me, as I had no clue what the “name” was until you told me.

Perhaps StringEnum is this way, as I understand, due to the Generated API beginning with PHP, which does not have a built-in enum class.

As things stand, me not being able to easily work with EntryStatus objects is a major roadblock in my project.

I hope the Kaltura Developers weigh in soon.

This has bugged me all day but I may have finally figured it out.

string status = typeof(EntryStatus).GetFields().FirstOrDefault(o => o.GetValue(null).ToString() == mediaEntry.Status.ToString()).Name;

This loops through all the fields of the EntryStatus class and returns the name of the field whose value matches the numeric value of the media entry status property. And here is an extension method that should work across all the different Kaltura enums.

	string status = mediaEntry.Status.Name();

	using System.Linq;
	public static class Extensions
		public static string Name<T>(this T kalturaEnum) where T: Kaltura.StringEnum
			return kalturaEnum?.GetType().GetFields().FirstOrDefault(o => o.GetValue(null).ToString() == kalturaEnum.ToString().Name);
1 Like

That is it! Thank you so very much!


I just updated the extension method with a null conditional operator to protect against a null exception. I’m glad I could help. Good luck with your project!


finaly you can reach your rank in rainbow six siege by using https://proboosting.net/