This project is read-only.


Enum.ToObject() should allow also typeof(T)


Would be helpfull for Enum flags to array (see below).
    public static IEnumerable<T> EnumFlagsToArray<T>(this Enum source) {
        if (source == null) {
            return new List<T>();
        return Enum.GetValues(typeof(T)).Cast<int>().Where(c => (c & (int) Enum.ToObject(typeof(T), source)) != 0).Cast<T>().ToList();
Closed Dec 16, 2013 at 2:44 PM by fickerra
Currently CS2HX does not support Enum.GetValues along with generics. When it sees a call to Enum.GetValues, it requires that the enum type is spelled out explicitly.

There's a few ways to work around this, depending on your needs.
  1. You can implement this in haxe manually. To do this, implement it some haxe class (let's call it HaxeUtility) add a line to Translations.xml that re-maps the method to your native one, such as: <Method SourceObject="SourceNamespace.SourceClass" Match="EnumFlagsToArray" ExtensionNamespace="HaxeUtility" />
  2. You can re-work calls to this to use Enum.GetValues() and use a separate method to filter down the ones you want. I don't believe you need the call to Enum.ToObject(). If you remove that, the rest of the code should work.
  3. You can extend CS2HX to support this use case. If you get it working, feel free to supply me with a patch and I'll integrate it.