Added support for ShellItemPropertyStore to be created with a PROPERTYKEY filter or an ICreateObject

pull/161/head
dahall 2020-07-16 08:38:45 -06:00
parent c727cfa055
commit ebbac20ca6
2 changed files with 25 additions and 7 deletions

View File

@ -326,8 +326,6 @@ namespace Vanara.Windows.Shell
SingleLine = 0x00000010,
}
// TODO: object GetPropertyStoreForKeys(IntPtr rgKeys, uint cKeys, GPS flags, in Guid riid);
// TODO: object GetPropertyStoreWithCreateObject(GPS flags, object punkCreateObject, in Guid riid);
/// <summary>Encapsulates an item in the Windows Shell.</summary>
/// <seealso cref="System.IComparable{ShellItem}"/>
/// <seealso cref="System.IDisposable"/>

View File

@ -30,6 +30,14 @@ namespace Vanara.Windows.Shell
PropertyChanged += propChangedHandler;
}
/// <summary>
/// Gets or sets the ICreateObject used instead of CoCreateInstance to create an instance of the property handler associated with
/// the Shell item on which this method is called. If this value is set, <see cref="PropertyFilter"/> will be ignored.
/// </summary>
/// <value>The creator object.</value>
[DefaultValue(null)]
public ICreateObject Creator { get; set; }
/// <summary>Gets or sets a value indicating whether to include slow properties.</summary>
/// <value><c>true</c> if including slow properties; otherwise, <c>false</c>.</value>
[DefaultValue(false)]
@ -63,6 +71,14 @@ namespace Vanara.Windows.Shell
}
}
/// <summary>
/// Gets or sets a set of properties used to filter the property store. This value can be <see langword="null"/>. This value will be
/// ignored if <see cref="Creator"/> is also set.
/// </summary>
/// <value>The list of properties used to filter.</value>
[DefaultValue(null)]
public PROPERTYKEY[] PropertyFilter { get; set; }
/// <summary>Gets or sets a value indicating whether properties can be read and written.</summary>
/// <value><c>true</c> if properties are read/write; otherwise, <c>false</c>.</value>
[DefaultValue(true)]
@ -105,6 +121,11 @@ namespace Vanara.Windows.Shell
}
}
/// <summary>Gets the CLSID of a supplied property key.</summary>
/// <param name="propertyKey">The property key.</param>
/// <returns>The CLSID related to the property key.</returns>
public Guid GetCLSID(PROPERTYKEY propertyKey) => shellItem?.iShellItem2?.GetCLSID(propertyKey) ?? Guid.Empty;
/// <summary>The IPropertyStore instance. This can be null.</summary>
protected override IPropertyStore GetIPropertyStore()
{
@ -112,6 +133,10 @@ namespace Vanara.Windows.Shell
return (IPropertyStore)lnk.link;
try
{
if (Creator != null)
return shellItem?.iShellItem2?.GetPropertyStoreWithCreateObject(flags, Creator, typeof(IPropertyStore).GUID);
if (PropertyFilter != null && PropertyFilter.Length > 0)
return shellItem?.iShellItem2?.GetPropertyStoreForKeys(PropertyFilter, (uint)PropertyFilter.Length, flags, typeof(IPropertyStore).GUID);
return shellItem?.iShellItem2?.GetPropertyStore(flags, typeof(IPropertyStore).GUID);
}
catch (COMException comex) when (comex.ErrorCode == HRESULT.E_FAIL)
@ -119,10 +144,5 @@ namespace Vanara.Windows.Shell
throw new InvalidOperationException($"The ShellItem does not support a property store with the flags: {flags}", comex);
}
}
/// <summary>Gets the CLSID of a supplied property key.</summary>
/// <param name="propertyKey">The property key.</param>
/// <returns>The CLSID related to the property key.</returns>
public Guid GetCLSID(PROPERTYKEY propertyKey) => shellItem?.iShellItem2?.GetCLSID(propertyKey) ?? Guid.Empty;
}
}