Fixed bug in ReadOnlyPropertyStore.TryGetValue (#219)

pull/212/head
dahall 2021-03-22 10:39:35 -06:00
parent b232e995ea
commit 035b30f146
2 changed files with 14 additions and 1 deletions

View File

@ -106,5 +106,13 @@ namespace Vanara.Windows.Shell.Tests
Assert.That(i.Properties.ReadOnly, Is.True);
Assert.That(i.Properties.Temporary, Is.False);
}
[Test]
public void PropXlsGetTest()
{
using ShellItem Item = new ShellItem(TestCaseSources.TempDirWhack + "Test.xlsx");
if (Item.Properties.TryGetValue(PROPERTYKEY.System.Document.PageCount, out int PageCount))
TestContext.Write($"PageCount={PageCount}");
}
}
}

View File

@ -181,7 +181,12 @@ namespace Vanara.Windows.Shell
/// When this method returns, the value associated with the specified key, if the key is found; otherwise, <c>default(T)</c>.
/// </param>
/// <returns><see langword="true"/> if the property store contains an element with the specified key; otherwise, <see langword="false"/>.</returns>
protected static bool TryGetValue<T>(IPropertyStore ps, PROPERTYKEY key, out T value) => (value = (T)ps.GetValue(key)) != null;
protected static bool TryGetValue<T>(IPropertyStore ps, PROPERTYKEY key, out T value)
{
var ret = ps.GetValue(key);
value = ret is null ? default : (T)ret;
return ret is not null;
}
/// <summary>The IPropertyStore instance. This can be null.</summary>
protected virtual IPropertyStore GetIPropertyStore() => iPropertyStore;