If you are using .NET 2.0 -> ProduceTopologyOrderedList returns List<IEntity>
If you are using .NET 1.x -> ProduceTopologyOrderedList returns ArrayList
I am definitely using 2.0, but I was able to get it working.
@MatthewM
the code you wrote is clean and nice and was exactly what I was looking for. Thank you much. I still got the same conversion error, I just changed the method somewhat.
Let me see what is different for me.
I ended up with this
public class CloneHelper
{
private CloneHelper()
{
}
internal static object CloneObject(object o)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
bf.Serialize(ms, o);
ms.Seek(0, SeekOrigin.Begin);
object oOut = bf.Deserialize(ms);
ms.Close();
return oOut;
}
internal static void ResetEntityAsNew(IEntity2 Entity)
{
Entity.IsNew = true;
Entity.IsDirty = true;
Entity.Fields.IsDirty = true;
for (int f = 0; f < Entity.Fields.Count; f++)
{
Entity.Fields[f].IsChanged = true;
}
}
public static IEntity2 CloneEntity(IEntity2 Entity)
{
IEntity2 newEntity;
newEntity = (IEntity2)CloneObject(Entity);
ObjectGraphUtils ogu = new ObjectGraphUtils();
ArrayList flatList = ogu.ProduceTopologyOrderedList(newEntity);
for (int f = 0; f < flatList.Count; f++)
ResetEntityAsNew((IEntity2)flatList[f]);
return newEntity;
}
}
}
Either way, your code got me where I needed to be and is greatly appreciated
Bob