Submitted by: bluesbreaker@gmail.com
The ParticipantCollection's GetHashCode() doesn't get updated as participants join and leave. This is (IMO) a bug in the .NET collections, as Hashtable and IDictionary exhibit the same behavior. I understand that handling OnParticipantJoin and OnParticipantLeave are preferred ways to handle changes in the ParticipantCollection, however; for stateless applications, its handy to store a reference the hashCode and simply compare it later to see if anything has changed.
Here's a sample implementation that should work for any ICollection implementation (sorry the paste looks so horrible):
private Int32 GetDeepHash(Object obj)
{
StringBuilder hashStr = new StringBuilder();
hashStr.Append(obj.GetType().Name + " [" + obj.ToString() + "] ");
if (obj is IEnumerable)
{
hashStr.Append("{");
IEnumerable enumObj = (obj as IEnumerable);
foreach (Object childObj in enumObj)
{
hashStr.Append(GetDeepHash(childObj) + ",");
}
hashStr.Append("}");
}
return hashStr.ToString().GetHashCode();
}