Search code examples
c#visual-studioclass-diagram

HashCode for a class in class diagram


I am trying to create class diagrams through code. Since CD files are XML files, it should be straight way to generate the files from classes. But the problem is I don't know how to get the hash code to embed in the type identifier.

Below is the XML generated by VS for a class.

<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
  <Class Name="NVTest.Program" Collapsed="true">
    <Position X="0.5" Y="0.5" Width="1.5" />
    <TypeIdentifier>
      <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAA=</HashCode>
      <FileName>Program.cs</FileName>
    </TypeIdentifier>
  </Class>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>

Assuming that the hashcode is a base64 string, I tried to generate it from class def. as

Convert.ToBase64String((BitConverter.GetBytes(typeof(Program).GetHashCode())))

but the result is: nJ4uAA==

So, how to generate the HashCode?

Thanks


Solution

  • While I don't know how that hashcode is generated, not having the HashCode element in .cd files doesn't seem to make a difference to the Class Diagram viewer. So you may try generating those files without any HashCode.