private static Type GetTypeForTypeInfo(ITypeInfo typeInfo)
        {
            // ReSharper disable EmptyGeneralCatchClause

            try
            {
                int index;
                var typeLib = typeInfo.GetContainingTypeLib(out index);

                var assembly = LoadPrimaryInteropAssembly(typeLib);
                if (assembly != null)
                {
                    var name = typeInfo.GetManagedName();
                    var guid = typeInfo.GetGuid();

                    var type = assembly.GetType(name, false, true);
                    if ((type != null) && (type.GUID == guid))
                    {
                        return(type);
                    }

                    var types = assembly.GetAllTypes().ToArray();
                    if ((index >= 0) && (index < types.Length))
                    {
                        type = types[index];
                        if ((type.GUID == guid) && (type.FullName == name))
                        {
                            return(type);
                        }
                    }

                    // ReSharper disable once PossibleNullReferenceException
                    type = types.FirstOrDefault(testType => (testType.GUID == guid) && (testType.FullName.Equals(name, StringComparison.OrdinalIgnoreCase)));
                    if (type != null)
                    {
                        return(type);
                    }
                }

                return(typeInfo.GetManagedType());
            }
            catch (Exception)
            {
            }

            return(null);

            // ReSharper restore EmptyGeneralCatchClause
        }
        public static Guid GetOrCreateGuid(this ITypeInfo typeInfo)
        {
            var guid = typeInfo.GetGuid();

            if (guid != Guid.Empty)
            {
                return(guid);
            }

            var guidBytes = typeInfo.GetContainingTypeLib().GetGuid().ToByteArray();

            var nameBytes = BitConverter.GetBytes(typeInfo.GetName().GetDigestAsUInt64());

            for (var index = 0; index < guidBytes.Length; index++)
            {
                guidBytes[index] ^= nameBytes[index % nameBytes.Length];
            }

            return(new Guid(guidBytes));
        }