|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Enumerations as keys in a Dictionary object
by Ilkka Kudjoi
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hi, In the server side I’ve got an (imaginary)
enumeration object, say ScaleType. public enum ScaleType { Kilograms
= 1, Pounds
= 2 } The enumeration is used as a key in a dictionary
property of a domain object, e.g. private Dictionary<ScaleType, System.Decimal?>
_scales = new Dictionary<ScaleType, System.Decimal?>(); public Dictionary<ScaleType, System.Decimal?>
scales { get { return this._scales; } set { this._scales = value; } } This domain object is then sent to the
client with the great help of FluorineFX. The resulting object has the enumeration
names as keys, not corresponding numeric values. For example, if we send this
object Dictionary<ScaleType,
System.Decimal?> scales = new Dictionary<ScaleType, System.Decimal?>
{ { ScaleType.Kilograms, 1m }, { ScaleType.Pounds, 1.5m } }; to the client, the result is var scales:Object = { “Kilograms”
: 1, “Pounds” : 1.5 }; not { “1” : 1, “2”
: 1.5 } as one could expect according to the conversion table http://www.fluorinefx.com/docs/fluorine/typeconversion.html. This behavior would be fine by us if the
enumeration would otherwise always convert to the string equivalent, but this
is not the case. If we send enumeration ScaleType.Kilograms to the client as a
property value inside a transferred domain object it is converted to Number (or
string equivalent if the AS property is string), not as text “Kilograms”.
This leads us into problems, the enumeration is converted in one case to strings
and in the other to Numbers. To conform the table mentioned above I guess that
Fluorine should convert the keys in the Dictionary object to the Number
equivalents. Could you comment this and fix the bug if it is one. Best regards, -- E-mail: ilkka.kudjoi@... _______________________________________________ fluorine mailing list fluorine@... http://fluorine.thesilentgroup.com/mailman/listinfo/fluorine_fluorine.thesilentgroup.com |
|
|
Re: Enumerations as keys in a Dictionary object
by Support-179
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hi,
Being
an integral type Enum values are sent as Number.
A dictionary (any IDictionary) is serialized as an
untyped object (associative array) where the keys of the dictionary are
converted to the string representation (ToString) of the key (they will
become properties of the untyped object).
This
is by design, the same applies for example to any numeric type
(and to non-primitive types!) as key in a
dictionary.
It is
can be considered that an IDictionary is a "special" case as the keys are always
sent as the string representation of the key (for the dictionary key the
conversion table does not apply).
Zoli
From: fluorine-bounces@... [mailto:fluorine-bounces@...] On Behalf Of Ilkka Kudjoi Sent: Monday, August 24, 2009 12:31 PM To: fluorine@... Subject: [Fluorine] Enumerations as keys in a Dictionary object Hi, In the server side I’ve got an (imaginary)
enumeration object, say ScaleType. public enum ScaleType
{
Kilograms = 1,
Pounds = 2
} The enumeration is used as a key in a
dictionary property of a domain object, e.g.
private Dictionary<ScaleType, System.Decimal?> _scales = new Dictionary<ScaleType, System.Decimal?>();
public Dictionary<ScaleType, System.Decimal?> scales
{
get { return
this._scales; }
set { this._scales = value; }
} This domain object is then sent to the
client with the great help of FluorineFX. The resulting object has the
enumeration names as keys, not corresponding numeric values. For example, if we
send this object Dictionary<ScaleType, System.Decimal?> scales = new Dictionary<ScaleType, System.Decimal?> { { ScaleType.Kilograms, 1m }, { ScaleType.Pounds, 1.5m } }; to the client, the result
is var scales:Object = { “Kilograms” : 1,
“Pounds” : 1.5 }; not { “1” : 1, “2” : 1.5 } as one could
expect according to the conversion table http://www.fluorinefx.com/docs/fluorine/typeconversion.html. This behavior would be fine by us if the
enumeration would otherwise always convert to the string equivalent, but this is
not the case. If we send enumeration ScaleType.Kilograms to the client as a
property value inside a transferred domain object it is converted to Number (or
string equivalent if the AS property is string), not as text “Kilograms”. This
leads us into problems, the enumeration is converted in one case to strings and
in the other to Numbers. To conform the table mentioned above I guess that
Fluorine should convert the keys in the Dictionary object to the Number
equivalents. Could you comment this and fix the bug if it is
one. Best regards, -- E-mail: ilkka.kudjoi@... _______________________________________________ fluorine mailing list fluorine@... http://fluorine.thesilentgroup.com/mailman/listinfo/fluorine_fluorine.thesilentgroup.com |
|
|
Re: Enumerations as keys in a Dictionary object
by Ilkka Kudjoi
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hi, Thanks for the
answer, we’ll manage this somehow. -
Ilkka From:
fluorine-bounces@...
[mailto:fluorine-bounces@...] On Behalf Of Support Hi, Being an integral type Enum values are sent as Number. A dictionary (any IDictionary) is serialized as an untyped
object (associative array) where the keys of the dictionary are converted to
the string representation (ToString) of the key (they will become
properties of the untyped object). This is by design, the same applies for example to any numeric type
(and to non-primitive types!) as key in a dictionary. It is can be considered that an IDictionary is a
"special" case as the keys are always sent as the string
representation of the key (for the dictionary key the conversion table does not
apply). Zoli From:
fluorine-bounces@...
[mailto:fluorine-bounces@...] On Behalf Of Ilkka
Kudjoi Hi, In the server side I’ve got an (imaginary)
enumeration object, say ScaleType.
public enum ScaleType
{
Kilograms = 1,
Pounds = 2
} The enumeration is used as a key in a
dictionary property of a domain object, e.g.
private Dictionary<ScaleType, System.Decimal?>
_scales = new Dictionary<ScaleType, System.Decimal?>();
public Dictionary<ScaleType, System.Decimal?>
scales
{
get { return this._scales; }
set { this._scales
= value; }
} This domain object is then sent to the
client with the great help of FluorineFX. The resulting object has the
enumeration names as keys, not corresponding numeric values. For example, if we
send this object Dictionary<ScaleType,
System.Decimal?> scales = new Dictionary<ScaleType, System.Decimal?>
{ { ScaleType.Kilograms, 1m }, { ScaleType.Pounds, 1.5m } }; to the client, the result is var scales:Object = { “Kilograms” : 1,
“Pounds” : 1.5 }; not { “1” : 1, “2” : 1.5 } as one could
expect according to the conversion table http://www.fluorinefx.com/docs/fluorine/typeconversion.html. This behavior would be fine by us if the
enumeration would otherwise always convert to the string equivalent, but this
is not the case. If we send enumeration ScaleType.Kilograms to the client as a
property value inside a transferred domain object it is converted to Number (or
string equivalent if the AS property is string), not as text “Kilograms”. This
leads us into problems, the enumeration is converted in one case to strings and
in the other to Numbers. To conform the table mentioned above I guess that
Fluorine should convert the keys in the Dictionary object to the Number
equivalents. Could you comment this and fix the bug if it is one. Best regards, -- E-mail: ilkka.kudjoi@... _______________________________________________ fluorine mailing list fluorine@... http://fluorine.thesilentgroup.com/mailman/listinfo/fluorine_fluorine.thesilentgroup.com |
| Free embeddable forum powered by Nabble | Forum Help |