예제 #1
0
        /// <summary>Retrieves the <see cref="Environment.SpecialFolder"/> associated with a <see cref="Shell32.KNOWNFOLDERID_Enum"/> if it exists.</summary>
        /// <param name="id">The known folder.</param>
        /// <returns>The <see cref="Environment.SpecialFolder"/> if defined, <c>null</c> otherwise.</returns>
        public static Environment.SpecialFolder?SpecialFolder(this Shell32.KNOWNFOLDERID_Enum id)
        {
            var attr = typeof(Shell32.KNOWNFOLDERID_Enum).GetField(id.ToString()).GetCustomAttributes(typeof(Shell32.KnownFolderDetailAttribute), false);
            var ret  = (Environment.SpecialFolder) 0XFFFF;

            if (attr.Length > 0)
            {
                ret = ((Shell32.KnownFolderDetailAttribute)attr[0]).Equivalent;
            }
            return(ret == (Environment.SpecialFolder) 0XFFFF ? (Environment.SpecialFolder?)null : ret);
        }
예제 #2
0
        /// <summary>Retrieves the Guid associated with a <see cref="Shell32.KNOWNFOLDERID_Enum"/>.</summary>
        /// <param name="id">The known folder.</param>
        /// <returns>The GUID.</returns>
        public static Guid Guid(this Shell32.KNOWNFOLDERID_Enum id)
        {
            var attr = typeof(Shell32.KNOWNFOLDERID_Enum).GetField(id.ToString()).GetCustomAttributes(typeof(Shell32.KnownFolderDetailAttribute), false);

            return(attr.Length > 0 ? ((Shell32.KnownFolderDetailAttribute)attr[0]).guid : System.Guid.Empty);
        }