Converted KnownFolderDetailAttribute to a derivative of AssociateAttribute

pull/10/head
David Hall 2018-01-11 08:59:14 -07:00
parent aee3e99e87
commit 41922e423d
2 changed files with 14 additions and 10 deletions

View File

@ -35,10 +35,15 @@ namespace Vanara.PInvoke
/// <summary>Retrieves the Guid associated with a <see cref="KNOWNFOLDERID"/>.</summary>
/// <param name="id">The known folder.</param>
/// <returns>The GUID.</returns>
public static Guid Guid(this KNOWNFOLDERID id)
public static Guid Guid(this KNOWNFOLDERID id) => AssociateAttribute.GetGuidFromEnum(id);
/// <summary>Retrieves the IShellItem associated with a <see cref="KNOWNFOLDERID"/>.</summary>
/// <param name="id">The known folder.</param>
/// <returns>The <see cref="IShellItem"/> instance.</returns>
public static IShellItem GetIShellItem(this KNOWNFOLDERID id)
{
var attr = typeof(KNOWNFOLDERID).GetField(id.ToString()).GetCustomAttributes(typeof(KnownFolderDetailAttribute), false);
return attr.Length > 0 ? ((KnownFolderDetailAttribute) attr[0]).guid : System.Guid.Empty;
SHGetKnownFolderItem(id.Guid(), KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, SafeTokenHandle.Null, typeof(IShellItem).GUID, out var ppv).ThrowIfFailed();
return (IShellItem) ppv;
}
/// <summary>Retrieves the <see cref="KNOWNFOLDERID"/> associated with the <see cref="Environment.SpecialFolder"/>.</summary>

View File

@ -992,17 +992,16 @@ namespace Vanara.PInvoke
/// <summary>Provides information about a <see cref="KNOWNFOLDERID"/>.</summary>
[AttributeUsage(AttributeTargets.Field)]
internal class KnownFolderDetailAttribute : Attribute
internal class KnownFolderDetailAttribute : AssociateAttribute
{
public Environment.SpecialFolder Equivalent = (Environment.SpecialFolder) 0XFFFF;
internal Guid guid;
/// <summary>Initializes a new instance of the <see cref="Vanara.PInvoke.Shell32.KnownFolderDetailAttribute"/> class with a GUID for the <see cref="KNOWNFOLDERID"/>.</summary>
/// <summary>Initializes a new instance of the <see cref="KnownFolderDetailAttribute"/> class with a GUID for the <see cref="KNOWNFOLDERID"/>.</summary>
/// <param name="knownFolderGuid">The GUID for the <see cref="KNOWNFOLDERID"/>.</param>
public KnownFolderDetailAttribute(string knownFolderGuid)
public KnownFolderDetailAttribute(string knownFolderGuid) : base(knownFolderGuid)
{
guid = new Guid(knownFolderGuid);
}
/// <summary>The equivalent SpecialFolder.</summary>
public Environment.SpecialFolder Equivalent = (Environment.SpecialFolder) 0XFFFF;
}
}
}