Weird issue comparing two IClass_ID

 
 
 
Posted by:psaii
Data created:6 August 2010

I've got two IClass_ID. First is a static one, created by :

MultiMaterialClassID    = Global.Class_ID.Create( (uint)BuiltInClassIDA.MULTI_CLASS_ID, 0 );

Second one is coming from an INode :

IClass_ID l_matId = Node.MaxNode.Mtl.ClassID

They have both the same content (multi material) : 0x200, 0

But in the watch window, the following returns FALSE :

l_matId == SceneExporter.MultiMaterialClassID false

Although a per component compare returns true !

l_matId.PartA == SceneExporter.MultiMaterialClassID.PartA true bool
l_matId.PartB == SceneExporter.MultiMaterialClassID.PartB true bool
l_matId.ToString() ==SceneExporter.MultiMaterialClassID.ToString() true bool

Am I missing something obvious tied to boxing, or something like that ?

Thanks,

---
Psaii

 

Straight comparison will not work in this case because the operator isn't carried over to interfaces and what you're doing, essentially, is comparing two references (which won't be the same unless its a reference to the same object).

I always compare class id's using their two components, as you showed. You can use a small utility function:

bool AreEqual( IClass_ID classId1, IClass_ID classId2 )
{
    return classId1.PartA == classId2.PartA && classId1.PartB == classId2.PartB;
}

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Makes sense, I'll continue to use the method mentionned,

Thanks,

---
Michel