title: Object to GUID/UUID
body: <p>I want to take any object and get a guid that represents that object.</p>
  
  <p>I know that entails a lot of things. I am looking for a good-enough solution for common applications.</p>
  
  <p>My specific use case is for caching, I want to know that the object used to create the thing I am caching has already made one in the past.  There would be 2 different types of objects. Each type contains only public properties, and may contain a list/ienumable.</p>
  
  <p>Assuming the object could be serializable my first idea was to serialize it to json (via native jsonserlizer or newtonsoft) and then take the json string and convert that to  a uuid version 5 as detailed in a gist here <a href="https://stackoverflow.com/questions/2190890/how-can-i-generate-a-guid-for-a-string">How can I generate a GUID for a string?</a></p>
  
  <p>My second approach if it's not serializable ( for example contained a dictionary ) would be to use reflection on the public properties to generate a unique string of some sort and then convert that to uuid version 5.</p>
  
  <p>Both approaches use uuid version 5 to take a string to guid. Is there a proven c# class that makes valid uuid 5 guids? The gist looks good but want to be sure.</p>
  
  <p>I was thinking of making the c# namespace and type name be the namespace for the uuid 5. Is that a valid use of namespace ?</p>
  
  <p>My first approach is good enough for my simple use case but I wanted to explore the second approach as it's more flexible.</p>
  
  <p>If creating the guid couldn't guarantee reasonable uniqueness it should throw an error. Surely super complicated objects would fail. How might I know that is the case if using reflection?</p>
  
  <p>I am looking for new approaches or concerns/implementations to the second approach.</p>
  
  <hr>
  
  <p>Edit: The reason why I bounty/reopened this almost 3 years later is because I need this again (and for caching again); but also because of the introduction of the generic unmanaged constraint in c# 7.3. The blog post at <a href="http://devblogs.microsoft.com/premier-developer/dissecting-new-generics-constraints-in-c-7-3/" rel="nofollow noreferrer">http://devblogs.microsoft.com/premier-developer/dissecting-new-generics-constraints-in-c-7-3/</a> seems to suggest that if the object can obey the unmanaged spec you can find a suitable key for a key-value store. Am I misunderstanding something? </p>
  
  <p>This is still limited because the object (generic) must obey the unmanaged type constraint which is very limiting (no strings, no arrays, etc), but its one step closer. I don't completely understand why the method of getting the memory stream and getting a sha1 hash cant be done on not unmanaged typed.</p>
  
  <p>I understand that reference types are pointing to places in memory and its not as easy to get the memory that represents all whole object; but it feels doable. After all, objects eventually are made up a bunch of implementations of unmanaged types (string is an array chars, etc)</p>
  
  <p>PS: The requirement of GUID is loose, any integer/string at or under 512 bits would suffice</p>