diff --git a/Windows.Shell.Common/ShellProperties/PropertyStore.cs b/Windows.Shell.Common/ShellProperties/PropertyStore.cs index e5521ffa..bf6e95a6 100644 --- a/Windows.Shell.Common/ShellProperties/PropertyStore.cs +++ b/Windows.Shell.Common/ShellProperties/PropertyStore.cs @@ -19,35 +19,32 @@ public class PropertyStore : IDictionary, IDisposable, INo /// The flags. protected GETPROPERTYSTOREFLAGS flags = GETPROPERTYSTOREFLAGS.GPS_DEFAULT; - /// An optional IBindCtx object, which provides access to a bind context. - protected System.Runtime.InteropServices.ComTypes.IBindCtx? iBindCtx = null; - /// If specified, the path to the file system item. - protected string? itemPath = null; - - /// Initializes a new instance of the class from a file system path. - /// A string that specifies the item path. - /// The optional property changed handler. - public PropertyStore(string path, PropertyChangedEventHandler? propChangedHandler = null) : this(path, GETPROPERTYSTOREFLAGS.GPS_DEFAULT) - { - if (propChangedHandler != null) - PropertyChanged += propChangedHandler; - } - - /// Initializes a new instance of the class. - protected PropertyStore() { } + protected PIDL? item = null; /// Returns a property store for an item, given a path or parsing name. /// A string that specifies the item path. /// One or more values from the GETPROPERTYSTOREFLAGS constants. /// An optional IBindCtx object, which provides access to a bind context. - protected PropertyStore(string path, GETPROPERTYSTOREFLAGS? flags = null, System.Runtime.InteropServices.ComTypes.IBindCtx? pbc = null) + public PropertyStore(string path, GETPROPERTYSTOREFLAGS flags = GETPROPERTYSTOREFLAGS.GPS_DEFAULT, System.Runtime.InteropServices.ComTypes.IBindCtx? pbc = null) { - itemPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(path)); - if (flags.HasValue) this.flags = flags.Value; - iBindCtx = pbc; + IntPtr bc = pbc != null ? Marshal.GetIUnknownForObject(pbc!) : default; + SHParseDisplayName(Path.GetFullPath(Environment.ExpandEnvironmentVariables(path)), bc, out item, 0, out _).ThrowIfFailed(); + this.flags = flags; } + /// Returns a property store for an item, given a path or parsing name. + /// The item ID List representing the object. + /// One or more values from the GETPROPERTYSTOREFLAGS constants. + public PropertyStore(PIDL id, GETPROPERTYSTOREFLAGS flags = GETPROPERTYSTOREFLAGS.GPS_DEFAULT) + { + item = id; + this.flags = flags; + } + + /// Initializes a new instance of the class. + protected PropertyStore() { } + /// Occurs when a property value changes. public event PropertyChangedEventHandler? PropertyChanged; @@ -394,15 +391,7 @@ public class PropertyStore : IDictionary, IDisposable, INo } /// The IPropertyStore instance. This can be null. - protected virtual IPropertyStore? GetIPropertyStore() - { - if (itemPath is not null) - { - SHGetPropertyStoreFromParsingName(itemPath, iBindCtx, flags, typeof(IPropertyStore).GUID, out var iPropertyStore).ThrowIfFailed(); - return iPropertyStore; - } - return null; - } + protected virtual IPropertyStore? GetIPropertyStore() => item is not null ? SHGetPropertyStoreFromIDList(item, flags) : null; /// Gets an enumeration of the keys in the property store. /// Keys in the property store.