I ve been trying to do something like this:
...
Mapper.CreateMap<IEnumerable<Foo>, IEnumerable<FooDto>>();
var fooDtos = Mapper.Map<IEnumerable<Foo>, IEnumerable<FooDto>>(foos);
Keep in mind that Foo is an entity but the properties are exactly the same that FooDto.
The Result of fooDtos is an empty enumerable
Tips?
ok Its simple I should have mapped like this :
Mapper.CreateMap<Foo, FooDto>();
and that works Doh!
Related
I'm trying to pass an array as a hint in string export, something like this:
extends Node
var things_list=["thing_1", "thing_2", "thing_3"]
export(String,*things_list) var current_thing=things_list[0]
why am I doing this?
I want to reuse the things_list & to do so I have to tediously write all the same values twice,
once in this list itself & once in export like this:
extends Node
var things_list=["thing_1", "thing_2", "thing_3"]
export(String,"thing_1", "thing_2", "thing_3") var current_thing=things_list[0]
this becomes really annoying with longer lists,
So is there anything like ...array in js
or something like *args in python? (as shown in the first example)
or are the values somehow stored in the export variable itself?
maybe like current_thing.export_hints[1] #thing_2
Those values are stored internally and there is no scripting access. And no, the parser does not understand any syntax for an array in export (nor array spread elsewhere for that matter).
However, there is something similar. You can define an enum:
enum things {thing_1, thing_2, thing_3}
export(things) var current_thing = things.thing_1
As you might remember, if you have an enum, you have a Dictionary. So you can still get the list of things like this:
var things_list = things.keys()
However, the enum will be of int, not of String. Which I don't know if it will be an issue. You can still get the corresponding String like this:
var things_list = things.keys()
print(things_list[current_thing])
And, of course, your other option is to use _get_property_list. It is not overly complicated:
var things_list := ["thing_1", "thing_2", "thing_3"]
var current_thing:String = things_list[0]
func _get_property_list() -> Array:
return [
{
"name": "current_thing",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM,
"hint_string": PoolStringArray(things_list).join(",")
}
]
I am trying to use a string ('npcName') as a variable name. So far I have tried casting dialogMap into a DynamicAccess object, but it gives me the error 'Invalid array access' when I try this:
var npcName:String = 'TestNPC';
var casted = (cast Registry.dialogMap:haxe.DynamicAccess<Dynamic>);
var tempname = casted[root.npcName[0].message];
trace(tempname);
'dialogMap' is an empty map which I want to fill like so:
Registry.dialogMap['message'] = root.npcName[0].message;
How can I use npcName, a string, in the above line of code? Is there a way to transform the string into something usable? Any help would be appreciated.
The haxe.DynamicAccess doesn't have array access (like map[key]), but is an abstract type for working with anonymous structures that are intended to hold collections of objects by the string key. It is designed to work with map.get(key) and map.set(key). It is basically a nicer wrapper around Reflect.field and Reflect.setField and does some safety checks with Reflect.hasField.
var variable = "my_key";
var value = 123;
var dynamicMap = new haxe.DynamicAccess<Dynamic>();
dynamicMap.set(variable, value);
I'm noticing you are doing very much cast and dynamic, so untyped code, which is a bit of contradiction in a typed language. What is the actual type of dialogMap?
Not sure you are aware of it but, Haxe has its own maps, which are fully typed, so you don't need casts.
var map = new Map<String, Int>();
map[variable] = value;
I think this article helps understanding how to work with dynamic (untyped) objects.
Tip; for testing such small functionalities you can doodle around on the try.haxe site : http://try.haxe.org/#4B84E
Hope this helps, otherwise here is some relevant documentation:
http://api.haxe.org/haxe/DynamicAccess.html
https://haxe.org/manual/std-reflection.html
https://haxe.org/manual/types-dynamic.html
http://code.haxe.org/category/beginner/string-variable-reflection.html
so I have been stuck with this problem for quite some time now.
I'm working with some data provided as JSON and retrieved via WSLITE using groovy.
So far handling the json structur and finding data was no problem since the webservice response provided by WSLITE
is retuned as an instance of JsonSlurper.
I now came across some cases where the structure that json response varies depending on what I query for.
Structure looks like this:
{
"result":[
...
"someId": [...]
"somethingElse": [...]
...
"variants":{
"0123":{
"description": "somethingsomething",
...,
...,
"subVariant":{
"1234001":{
name: "somename",
...
}
}
},
"4567":{
"description": "somethingsomething",
...,
...,
"subVariant":{
"4567001":{
name: "somename"
...
...
}
}
}
}
]
}
As you can see, the variants node is an object holding another nested object which holds even more nested objects.
The problem here is that the variants node sometimes holds more than one OBJECT but always at least one. Same vor the subVariant node.
Furthermore I do not now the name of the (numeric) nodes in advance. hence i have to build the path dinamically.
Since Json is handled as maps, lists and arrays in groovy I thought I was able to do this:
def js = JsonSlurper().parseText(jsonReponse)
println js.result.variants[0].subVariant[0].name //js.result.variants.getClass() prints class java.util.ArrayList
but that returns null
while accessing the data statically like this:
println "js.result.variants."0123".subVariant."1234001".name
works just fine.
Just pinting the variants like this
println js.result.variants
also works fine. it prints the first (and only) content of the whole variants tree.
My question is: Why is that?
It kind of seems like i can not address nexted objects by index... am i right? how else would i got about that?
thanks in advance.
Well the reason you cant access it using [0] is simply because "variants": { ... isnt an array, that would look like this: "variants" :[ ...
So your variants is an object with a variable number of attributes, which is basically a named map.
However, if you dont know the entry names, you can iterate through these using .each, so you could do something like js.result.variants.each{key, val -> println val.description}
And something similar for the subvariant
I dont know how to describe the problem, so weird. I have function like this:
long getPersonId(...){
//...
}
The above function returns Id of a person based on some arguments.
So I logged the return value of the function and it is 1.
Then I have code like this:
person = myMap.get(getPersonId(..))
which returns null object but this returns a valid Person object, why?:
person = myMap.get(1)
But as I described before getPersonId(..) returns 1, which basically means
myMap.get(getPersonId(..)) == myMap.get(1)
myMap is typed as Map<Long, Person> myMap
What is happening here?
In Groovy, as in Java, 1 is an int literal, not a long, so
myMap.get(1)
is attempting to look up the key Integer.valueOf(1), whereas
myMap.get(getPersonId(..))
is looking up the key Long.valueOf(getPersonId(...)). You need to make sure that when you populate the map you are definitely using Long keys rather than Integer ones, e.g.
myMap.put(1L, somePerson)
In your original version of this question you were calling the GORM get method on a domain class rather than the java.util.Map.get method, and that should work as required as the GORM method call converts the ID to the appropriate type for you before passing it on to Hibernate.
I am so sorry the problem was when I initialize the map myMap
Map<Long, Person> myMap = [1, new Person()]
when you say something like this the key is an integerbut not a long still groovy not complaining.
So the problem is my method was returning a long value (1L) but my actual key on the map is integer value(1).
So changing my map init to Map<Long, Person> myMap = [1L, new Person()] solved the problem.
Probably this due to dynamic nature groovy but irritating unless you know how dynamic langs behave lol.
I want to know how to use a variable string to reference a movie clip in a hierarchy in AS2.
For example, and please forgive my newbie coding:
If my variable is defined as:
_root.MovieName = "Bob";
Then I'd like to be able to write:
_root.MovieName.ChildClip.gotoAndPlay("Label");
Where MovieName is the string "Bob" and not an actual instance called "MovieName". So Flash looks for an instance of "Bob" and goes into the child clips from there.
Is there any way to do this?
_root actually is a reference to the "root" of the movie, which also inherits a bunch of properties, it behaves like an object, so yes, you can do things like the following:
trace(_root["Bob"]); //Should return the instance.
var movieName = "Bob";
trace(_root[movieName]); //Should be the same.
I FOUND THE ANSWER!
In order to refer to movie clip instances using variables, first declare that variable as a string, then use the this[] handler. Here is the code that worked for me and the page that held it:
// CREATE THE STRING
var newString:String = "movieClipInstanceName";
// ASSUMING YOU ALREADY HAVE A MOVIECLIP WITH AN INSTANCE NAME OF "movieClipInstanceName" ON STAGE,
//CHANGE THE ALPHA OF THE MOVIECLIP TO 0
this[newString].alpha = 0;
And the page:
http://www.kirupa.com/forum/showthread.php?327501-Converting-String-to-Movie-Clip-Instance-Name
Big thanks to everyone who pitched in to help me!