Exemple #1
0
        /// <summary>
        /// This method generates a PROGID for the specified type. If the type has
        /// a PROGID in the metadata then it is returned otherwise a stable PROGID
        /// is generated based on the fully qualified name of the type.
        /// </summary>
        public static string GenerateProgIdForType(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (type.IsImport)
            {
                throw new ArgumentException(SR.Argument_TypeMustNotBeComImport, nameof(type));
            }
            if (type.IsGenericType)
            {
                throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(type));
            }

            ProgIdAttribute progIdAttribute = type.GetCustomAttribute <ProgIdAttribute>();

            if (progIdAttribute != null)
            {
                return(progIdAttribute.Value ?? string.Empty);
            }

            // If there is no prog ID attribute then use the full name of the type as the prog id.
            return(type.FullName);
        }