I was working on COM Interop, and I got troubled with creating a Guid record every time I need to call a function that needs one.

You see, a GUID is associated with an interface declaration, and since it's in the interface, why should I have to copy and paste the GUID, when I specify the type?

Here's an example of an interface declaration.

  [ComImport, Guid('CB2F6722-AB3A-11D2-9C40-00C04FA30A3E'),
   InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  ICorRuntimeHost = interface
  ...
  end;

So, I wrote a helper function that takes a given type, and returns the Guid declared on the type with the GuidAttribute.

function AttrToGuid(AType: System.Type): Guid;
var
 Attrs: array of TObject;
begin
  Attrs := AType.GetCustomAttributes(typeof(GuidAttribute), False);
  Result := System.Guid.Create(GuidAttribute(Attrs[0]).Value);
end;

And here's how you call it...

AttrToGuid(typeof(ICorRuntimeHost));

While working on the code, I came across Oleg Lvovitch's Blog, about custom attributes.