R
RedLars
Hi,
Given this class definition,
public class Node
{
Node parent;
object current;
ArrayList children;
}
I would need to type check the object variable everytime I'd need to
use it. Like shown below;
void SomeMethod(Node node)
{
object obj = node.current;
if (obj is SomeType1)
{
// code
}
else if (obj is SomeType2)
{
// code
}
else if (obj is SomeType3)
{
// code
}
}
Is such a type check at runtime a bad thing in c#? Would using a
visitor patterns' double dispatch be a more elegant solution? This
would lead to changing the original Node to;
public class Node
{
Node parent;
baseObject current; // change from object to base class in apps'
object model
ArrayList children;
}
and adding the neccessary interfaces etc. Suppose it would make the
Node class less usable for other purposes - i,e, by binding it to a
specific object model.
Given this class definition,
public class Node
{
Node parent;
object current;
ArrayList children;
}
I would need to type check the object variable everytime I'd need to
use it. Like shown below;
void SomeMethod(Node node)
{
object obj = node.current;
if (obj is SomeType1)
{
// code
}
else if (obj is SomeType2)
{
// code
}
else if (obj is SomeType3)
{
// code
}
}
Is such a type check at runtime a bad thing in c#? Would using a
visitor patterns' double dispatch be a more elegant solution? This
would lead to changing the original Node to;
public class Node
{
Node parent;
baseObject current; // change from object to base class in apps'
object model
ArrayList children;
}
and adding the neccessary interfaces etc. Suppose it would make the
Node class less usable for other purposes - i,e, by binding it to a
specific object model.