Getorb this orb value is used for a lot during

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t to calculate the hash code for.</param> /// <returns>The hash code.</returns> public static int ObjectHashCode(object obj) { return ObjectHashCode(obj, GetReadablePropertyNames(obj)); } public static int ObjectHashCode(object obj, string properties) { ArrayList values = UnwrapObjectDownToSimpleTypes(obj, properties); int hashCode = obj.GetType().FullName.GetHashCode(); foreach (object simpleObject in values) { if (simpleObject != null) { hashCode += simpleObject.GetHashCode(); hashCode += simpleObject.ToString().GetHashCode(); hashCode *= 29; } } return hashCode; } public static bool AreObjectsEqual(object obj1, object obj2) { return AreObjectsEqual(obj1, obj2, GetReadablePropertyNames(obj1)); } public static bool AreObjectsEqual(object obj1, object obj2, string properties) { if (obj1 == null && obj2 != null) return false; if (obj1 != null && obj2 == null) return false; if (obj1 == null && obj2 == null) return true; if (obj1.GetType() != obj2.GetType()) return false; ArrayList obj1Values = UnwrapObjectDownToSimpleTypes(obj1, properties); ArrayList obj2Values = UnwrapObjectDownToSimpleTypes(obj2, properties); if (obj1Values.Count != obj2Values.Count) return false; for (int i = 0; i < obj1Values.Count; i++) { if (obj1Values[i] != obj2Values[i]) return false; } return true; } public static ArrayList UnwrapObjectDownToSimpleTypes(object obj, ArrayList objectValues) { return UnwrapObjectDownToSimpleTypes(obj, GetReadablePropertyNames(obj), objectValues); } public static ArrayList UnwrapObjectDownToSimpleTypes(object obj, string properties) { return UnwrapObjectDownToSimpleTypes(obj, properties, new ArrayList()); } public static ArrayList UnwrapObjectDownToSimpleTypes(object obj, string properties, ArrayList objectValues) { ArrayList alreadyDigested = new ArrayList(); int hashcode = obj.GetType().FullName.GetHashCode(); for (int i = 0; i < properties.Length; i++) { object value = GetProperty(obj, properties[i]); if (value...
View Full Document

This document was uploaded on 10/12/2012.

Ask a homework question - tutors are online