-
Notifications
You must be signed in to change notification settings - Fork 62
Object members switch #7446
Comments
Maybe rather than using |
Some ideas..
value memberMap = map {
`PersonDb.personAge` -> `PersonDto.age`,
`PersonDb.personName` -> `PersonDto.name`
};
class PersonDb(
Integer id,
mapToDto(`PersonDto.name`) shared String personName,
mapToDto(`PersonDto.age`) shared Integer personAge
){} |
@Voiteh would it work for you if these were declaration references, i.e. switch (dec)
case (value PersonDto.name) { .... }
case (value PersonDto.age) { .... } |
@gavinking I think so, as I just need to somehow connect references. Would it be possible to have exhausting |
@Voiteh well generally we don't consider a |
@gavinking I'm bit confused, how could You declare member using |
@Voiteh well, here's an example of a class with an enumerated list of elements: class Suit of hearts | diamonds | clubs | spades {
String name;
shared new hearts { name = "hearts"; }
shared new diamonds { name = "diamonds"; }
shared new clubs { name = "clubs"; }
shared new spades { name = "spades"; }
} Note that all the elements (constructors) are listed in the |
@gavinking Ah I see what You ment now. As for what I wrote "Is this, what You presented possible it in Ceylon 1.3.3" I ment : switch (dec)
case (value PersonDto.name) { .... }
case (value PersonDto.age) { .... } I couldn't make it compile in web IDE so i guess no... |
No, it's not possible today, but in principle it would be pretty simple to add. |
When using metamodel, for object information extraction, like member attributes or member functions. It would be nice to have possibility to switch over this extracted values.
For example I would like to create mapping between two representation of the same domain model, a DTO and database model, for some reason names of attributes does not match.
Currently the simplest form of mapping between those two attributes I can make, look like:
And it would be nice to have something like this:
Of course with exhausting requirement "Case types must cover all cases of the switch type or an else clause must appear"
The text was updated successfully, but these errors were encountered: