Skip to content

Commit

Permalink
Merge pull request #141 from Numpsy/TryGetValue
Browse files Browse the repository at this point in the history
Rework OLEProperties.GetDescription to avoid allocating temporary dictionaries
  • Loading branch information
ironfede authored Sep 2, 2024
2 parents 1eb2a93 + 7c8438f commit d68e70f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions sources/OpenMcdf.Extensions/OLEProperties/ProperyIdentifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,26 @@ public static class CommonIdentifiers

public static class Extensions
{
public static String GetDescription(this uint identifier, ContainerType map, Dictionary<uint, string> customDict = null)
public static string GetDescription(this uint identifier, ContainerType map, Dictionary<uint, string> customDict = null)
{
Dictionary<uint, string> NameDictionary = new Dictionary<uint, string>();
Dictionary<uint, string> nameDictionary = customDict;

if (customDict == null)
if (nameDictionary is null)
{
switch (map)
{
case ContainerType.SummaryInfo:
NameDictionary = CommonIdentifiers.PropertyIdentifiersSummaryInfo;
nameDictionary = CommonIdentifiers.PropertyIdentifiersSummaryInfo;
break;
case ContainerType.DocumentSummaryInfo:
NameDictionary = CommonIdentifiers.PropertyIdentifiersDocumentSummaryInfo;
nameDictionary = CommonIdentifiers.PropertyIdentifiersDocumentSummaryInfo;
break;
}
}
else
{
NameDictionary = customDict;
}

if (NameDictionary.ContainsKey(identifier))
if (nameDictionary?.TryGetValue(identifier, out string value) == true)
{
return NameDictionary[identifier];
return value;
}

return "0x" + identifier.ToString("x8");
Expand Down

0 comments on commit d68e70f

Please sign in to comment.