Welcome,
Guest
. Please
login
or
register
.
May 12, 2025, 11:16:06 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
TNet 3 Support
»
DataNode children Insert
« previous
next »
Print
Pages: [
1
]
Author
Topic: DataNode children Insert (Read 4251 times)
devomage
Sr. Member
Thank You
-Given: 7
-Receive: 67
Posts: 250
DataNode children Insert
«
on:
May 16, 2017, 10:54:07 PM »
Any chance of adding a convenience method to deal with reordering DataNode children?
I do not see a canned method to achieve this...
Something like:
System.
Collections
.
Generic
.
List
<
string
>
list
=
new
System.
Collections
.
Generic
.
List
<
string
>
(
)
;
list
.
Insert
(
index, item
)
;
Logged
devomage
Sr. Member
Thank You
-Given: 7
-Receive: 67
Posts: 250
Re: DataNode children Insert
«
Reply #1 on:
May 16, 2017, 11:03:55 PM »
list
.
RemoveAt
(
index
)
;
Logged
devomage
Sr. Member
Thank You
-Given: 7
-Receive: 67
Posts: 250
Re: DataNode children Insert
«
Reply #2 on:
May 16, 2017, 11:20:14 PM »
I guess not so much the remove function - RemoveChild works fine for this. Insert though is still an issue...
This is currently working:
private
DataNode InsertAt
(
DataNode list,
int
index, DataNode item
)
{
bool
isSet
=
false
;
DataNode new_list
=
new
DataNode
(
"character_list"
)
;
for
(
int
i
=
0
;
i
<
list
.
children
.
Count
;
i
++
)
{
DataNode node
=
list
.
children
[
i
]
;
if
(
i
==
index
)
{
isSet
=
true
;
new_list
.
SetHierarchy
(
item
.
name
, item
)
;
}
new_list
.
SetHierarchy
(
node
.
name
, node
)
;
}
if
(
!
isSet
)
{
new_list
.
SetHierarchy
(
item
.
name
, item
)
;
}
return
new_list
;
}
Logged
devomage
Sr. Member
Thank You
-Given: 7
-Receive: 67
Posts: 250
Re: DataNode children Insert
«
Reply #3 on:
May 17, 2017, 07:20:38 PM »
I went a different route, but this is a nice extension...
public
static
DataNode InsertAt
(
this
DataNode list,
int
index, DataNode item
)
{
bool
isSet
=
false
;
DataNode new_list
=
new
DataNode
(
list
.
name
)
;
for
(
int
i
=
0
;
i
<
list
.
children
.
Count
;
i
++
)
{
DataNode node
=
list
.
children
[
i
]
;
if
(
i
==
index
)
{
isSet
=
true
;
new_list
.
SetHierarchy
(
item
.
name
, item
)
;
}
new_list
.
SetHierarchy
(
node
.
name
, node
)
;
}
if
(
!
isSet
)
{
new_list
.
SetHierarchy
(
item
.
name
, item
)
;
}
return
new_list
;
}
Logged
cmifwdll
Global Moderator
Sr. Member
Thank You
-Given: 0
-Receive: 149
Posts: 285
TNet Alchemist
Re: DataNode children Insert
«
Reply #4 on:
May 17, 2017, 11:09:09 PM »
Since children is just a List<DataNode> which is basically a DataNode[] wouldn't normal re-ordering / insertion work?
TNet
.
DataNode
node
=
new
TNet
.
DataNode
(
"NodeRoot"
,
0
)
;
node
.
AddChild
(
"ChildOne"
,
1
)
;
node
.
AddChild
(
"ChildTwo"
,
2
)
;
node
.
AddChild
(
"ChildThree"
,
3
)
;
node
.
AddChild
(
"ChildFour"
,
4
)
;
node
.
AddChild
(
"ChildFive"
,
5
)
;
TNet
.
DataNode
tempChildThree
=
node
.
children
[
2
]
;
node
.
children
[
2
]
=
node
.
children
[
4
]
;
node
.
children
[
4
]
=
tempChildThree
;
node
.
children
.
Insert
(
2
,
new
TNet
.
DataNode
(
"InsertedChildThree"
,
3
)
)
;
Debug
.
Log
(
"Test DataNode: "
+
node
.
ToString
(
)
)
;
Produces:
Test DataNode
:
NodeRoot
=
0
ChildOne
=
1
ChildTwo
=
2
InsertedChildThree
=
3
ChildFive
=
5
ChildFour
=
4
ChildThree
=
3
This seems to be what the SetHiearchy function does, except it traverses the tree to find the specified child at the passed path.
Logged
devomage
Sr. Member
Thank You
-Given: 7
-Receive: 67
Posts: 250
Re: DataNode children Insert
«
Reply #5 on:
May 18, 2017, 05:20:51 PM »
wow, for the life of me I didnt see Insert there when I posted this thread...
thanks cmifwdll, Insert is def the way to go.
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
TNet 3 Support
»
DataNode children Insert