Object members switch
See original GitHub issueWhen 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.
class PersonDb(Integer id,shared String personName,shared Integer personAge){}
class PersonDto(shared String name,shared Integer age ){}
Currently the simplest form of mapping between those two attributes I can make, look like:
Attribute<PersonDto>? mapAttributes(Attribute<PersonDb> dbAttribute) =>
if(dbAttribute==`PersonDb.personAge`) then `PersonDto.age`
else if(dbAttribute==`PersonDb.personName`) then `PersonDto.name`
else null;
And it would be nice to have something like this:
Attribute<PersonDto>? mapSwitchAttributes(Attribute<PersonDb> dbAttribute) =>
switch(dbAttribute)
case(is `PersonDb.personAge`){
return `PersonDto.age`;
}
case(is `PersonDb.personName`){
return `PersonDto.name`;
}else{
return null;
}
Of course with exhausting requirement “Case types must cover all cases of the switch type or an else clause must appear”
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Can I check for object properties in a switch statement?
Simple answer is no, it is not supported,. As a workaround you may try to use following form of switch: switch (true) {...
Read more >Switch case with an object - JavaScript - SitePoint Forums
Hi All, I need some help with JS which is a part of a sigma grid ajax function. Here's an array with variable...
Read more >Working with objects - JavaScript - MDN Web Docs - Mozilla
An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's...
Read more >Replacing switch statements with Object literals
Let's set up a simple Object literal that returns a String value only. We might, however, need more complex code than a String...
Read more >Switch | Object Players Official Wiki | Fandom
Switch is a handheld game console, He has a big black box with a grey screen. He also has two blue and red...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, it’s not possible today, but in principle it would be pretty simple to add.
Some ideas…
PersonDb
orPersonDto
like: