How to get a unique id for a method based on its signature in c#?

.net, c#, reflection

Solution

How unique does it have to be? What size?

If you just concatenate the return type and every argument type using commas, you have a string that uniquely identifies this signature. It also happens to fully encode the signature, but that's not necessarily bad.

If you want something shorter, you could:

- hash it using a cryptographic hash function. Slow, the hash is long, but extremely likely to be unique

- hash it using a simple hash function. Collisions might occur, but the Id is shorter.

- store them in some sort of a lookup table or database. Your IDs are then just sequential integers.

Problem

Is there anyway i could get a uniqueId for every method in a specific class using reflection based on its signature? I am aware of the GetHashCode method, but I want guaranteed uniqueness.

Original source

Related problems