I am creating an .idl file programmatically. How do I create UUIDs for the interfaces and Methods Programmatically.
Can I generate the UUID programmatically?
I am creating an .idl file programmatically. How do I create UUIDs for the interfaces and Methods Programmatically.
Can I generate the UUID programmatically?
Here is a client side "sequential guid" solution.
http://www.pinvoke.net/default.aspx/rpcrt4.uuidcreate
Keywords: CreateSequentialUUID SequentialUUID
Be careful: while the string representations for .NET Guid and (RFC4122) UUID are identical, the storage format is not. .NET trades in little-endian bytes for the first three
Guid
parts.If you are transmitting the bytes (for example, as base64), you can't just use
Guid.ToByteArray()
and encode it. You'll need toArray.Reverse
the first three parts (Data1-3).I do it this way:
See this answer for the specific .NET implementation details.
Edit: Thanks to Jeff Walker, Code Ranger, for pointing out that the internals are not relevant to the format of the byte array that goes in and out of the byte-array constructor and
ToByteArray()
.I don't know about methods; however, the type to GUID can be done via:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.generateguidfortype.aspx
I have a GitHub Gist with a Java like UUID implementation in C#: https://gist.github.com/rickbeerendonk/13655dd24ec574954366
The UUID can be created from the least and most significant bits, just like in Java. It also exposes them. The implementation has an explicit conversion to a GUID and an implicit conversion from a GUID.
You are probably looking for
System.Guid.NewGuid()
.