So I need to retrieve an enums min and max values to pass into a randomizer function for some unit testing to generate random enum values. However it needs to generate an enum member value based upon whatever random enum type is passed in.
This is what I have found so far that is close but need to call it passing the type dynamically.
So I want to call it like thisCode:public T RandomEnum<T>() { T[] values = (T[])Enum.GetValues(typeof(T)); return values[new Random().Next(0, values.Length)]; }
Code:var test = 0; test = RandomEnum<selfProp.PropertyType>();





Reply With Quote