pivot-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bartlett <cbartlet...@gmail.com>
Subject Re: Automated support for enums
Date Tue, 07 Sep 2010 13:52:15 GMT
On 7 September 2010 19:25, Greg Brown <gkbrown@mac.com> wrote:

>
> > If so, then how about first attempting a valueOf using the raw attribute
> > value from the BXML?  If that fails, then try with the uppercase ersion.
> > That would allow case sensitive, mixed case values to be supplied in
> BXML.
>
> I thought about that, but it didn't seem very elegant, especially since the
> first attempt will fail for pretty much every use of an enum in BXML.  :-)
>
> I don't see frequent failures as a problem, especially if it allows for
both case sensitive & insensitive generalised enum processing. If you feel
that there will be a strong bias towards the first check failing, then
simply reorder the 2 check as mentioned previously.


Perhaps there are some subtleties with reflection on enums that I am
missing, or the full aim of the proposal, as I cant see what the complexity
here.

Feel free to skip and not respond to what follows unless it might help
further the discussion.  :)

Are these assumptions correct?
1) BXML should allow enum values to be supplied in a case insensitive manner
2) BXML should support all enums regardless of whether they are part of the
Pivot code base, and not impose any naming conventions  for the enum or its
values
3) Enum values are case sensitive, but finite and enumerable
4) An enum can contain multiple values whose names might be equal after a
toUpperCase()/toLowerCase() conversion
public enum MyEnum {
    value,
    VALUE,
    vALUe
}

If so, surely it is just a matter of looking through the enum's values and
choosing one based on some documented policy, such as
- Choose the enum value that matches the supplied value in a case sensitive
manner
- (Optionally perform upper and lower case tests independently in a defined
order)
- Otherwise choose the first value that matches in a non-case sensitive
manner
- Throw a 'EnumValueNotFoundException'

Chris

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message