mirror of https://github.com/dahall/Vanara.git
Converted KnownFolderDetailAttribute to a derivative of AssociateAttribute
parent
aee3e99e87
commit
41922e423d
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue