Repository navigation
Replies: 1 comment 1 reply
|
This is not supported. What's your scenario why would you want that? One possible solution would be a virtual method that returns an enum value for each type. E.g. enum Type
{
Foo,
Bar
}
class Foo
{
public virtual Type GetType() => Type.Foo;
}
class Bar : Foo
{
public override Type GetType() => Type.Bar;
} |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is there a way compare if the type of two objects are the same? In C# it would be:
if (A.GetType() == B.GetType())
and java
obj1.getClass().equals(obj2.getClass())
In fusion you could do it if there was just one type:
if(A is TypeX && B is TypeX)
But the problem comes in when you have base and derived types and you need to know if they are the same derived type. Using the snippet above it could be done. But it gets cumbersome fast when you have a number of derived types.
some thing like this:
if(A is TypeX && B is TypeX || A is TypeY && B is TypeY || A is TypeZ && B is TypeZ || ... etc
// A and B are pointers of the base type.
But what if the user of your library defines another derived type? There's no way to capture that this way.
All reactions