On 04/04/2013 08:50 PM, Chad Joan wrote:

> There has to be a better way!

You seem to be looking for the (to me) only sensible use of 'with': :)

enum SANE_Status
{
    SANE_STATUS_GOOD = 0,
    SANE_STATUS_UNSUPPORTED,
}

void foo(SANE_Status s)
{
    final switch (s) with (SANE_Status) {
    case SANE_STATUS_GOOD: break;
    case SANE_STATUS_UNSUPPORTED: break;
    }
}

void main()
{
    foo(SANE_Status.SANE_STATUS_GOOD);
}

If acceptable for you, I also recommend dropping the SANE_STATUS_ prefix from the values:

enum SANE_Status
{
    GOOD = 0,
    UNSUPPORTED,
}

void foo(SANE_Status s)
{
    final switch (s) with (SANE_Status) {
    case GOOD: break;
    case UNSUPPORTED: break;
    }
}

void main()
{
    foo(SANE_Status.GOOD);
}

Further, camel-casing the type and the values:

enum SaneStatus
{
    good = 0,
    unsupported,
}

void foo(SaneStatus s)
{
    final switch (s) with (SaneStatus) {
    case good: break;
    case unsupported: break;
    }
}

void main()
{
    foo(SaneStatus.good);
}

Ali

Reply via email to