Design-time alternatives to a GUID? [closed]
This isn't a complicated question. I was just thinking through best practice and thought the community might be able to help.
SOLUTION
Have one file that contains an enumeration. Source control can take care of collisions between multiple projects / developers. If all assemblies are compiled and deployed at the same time, the ID will be unique (if cast to int). Alternatively, we could assign a number to each enum. The enum file will be added to each project via "Add As Link".
Original question
I'd like a unique id that begins at one, is set at design time, and is easy to implement in code to identify different classes. In Visual Studio, we have a Tools / Create GUID. That's convenient, but at 16 bytes it's a little larger than I'd like.
It'd be nice to able to retrieve unique sequential integers from a web service.
Has someone already done this? Does such a service already exist?
One alternative is to have a file that acts as a central register for developers... but I'd rather not if possible. It would be nice to have two steps: 1. create class, 2. assign id. Done.
You can create this yourself if you want, make a web service and generate numbers. If you generate the number at design time, alter your code at design time so that no other program cares what your magic number is.
GUIDs can be created relatively quickly on anyone's computer. This means that you don't have to have some "central" database for numbers, which assists performance of certain applications. Otherwise, use the GUID, which is a globally unique identifier that you can generate at run time and design time.
精彩评论