document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. class HashcodeGenerator
  3. {
  4. public int GetHashCodeForArbitaryType<TType>(TType complexObject)
  5. {
  6. Type objectType = complexObject.GetType();
  7. PropertyInfo[] properties = objectType.GetProperties().OrderByDescending(x => x.Name).ToArray();
  8.  
  9. object firstValue = properties[0].GetValue(complexObject);
  10. int hashCode = firstValue?.GetHashCode() ?? 0;
  11.  
  12. for (int propertyIndex=1; propertyIndex < properties.Length; propertyIndex++)
  13. {
  14. object value = properties[propertyIndex].GetValue(complexObject);
  15. unchecked
  16. {
  17. hashCode = (hashCode * 397) ^ (value?.GetHashCode() ?? 0);
  18. }
  19. }
  20. return hashCode;
  21. }
  22. }
  23.  
');