I need to attach a unique identifier to objects at runtime. The identifier must be unique for the duration of the application. I plan to do this my having a private member
I would recommend using an integer value, and auto-incrementing it on assignment. You could use Interlocked.Increment to make this operation thread safe.
Most likely, a 32bit integer will be large enough for this task. I would recommend something like:
private static newObjectId = int.MinValue;
private static int GetNextId()
{
return Interlocked.Increment(ref newObjectId);
}
You can then use that in your base class for assigning a new, unique identifier.