Possible Duplicate:
.NET unique object identifier
Instead of re-inventing the wheel, is there a unique, immutable object ID I can access for each object instance in .NET?
I'm asking this because I find myself writing the same code many times: Add a field or a property named Id, with type of Guid
. This is useful mainly for logging purpose.
Example:
Logger.Debug(string.Format("about to save data to file, my id is {0}", this.Id));
Is there something built in the .NET framework instead of coding and using this.Id
?
Surely there's nothing immediate, but maybe something using .NET internals.
Update:
I intentionally don't want to use the GetHashCode
technique, or any related hash code mechanism.