Skip to content

Commit

Permalink
performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenbe committed Feb 21, 2024
1 parent 126b224 commit 9ac6746
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal override IFieldValue FromJson(JsonElement json)

internal override IFieldValue FromListDataAsStream(Dictionary<string, string> properties)
{
if (!properties.ContainsKey("lookupId"))
if (!properties.TryGetValue("lookupId", out string value))
{
LookupId = -1;
IsSecretFieldValue = false;
Expand All @@ -118,19 +118,16 @@ internal override IFieldValue FromListDataAsStream(Dictionary<string, string> pr
}
else
{
if (properties.ContainsKey("lookupId"))
{
LookupId = int.Parse(properties["lookupId"]);
}
LookupId = int.Parse(value);

if (properties.ContainsKey("lookupValue"))
if (properties.TryGetValue("lookupValue", out string valueLookupValue))
{
LookupValue = properties["lookupValue"];
LookupValue = valueLookupValue;
}

if (properties.ContainsKey("isSecretFieldValue"))
if (properties.TryGetValue("isSecretFieldValue", out string valueIsSecretValue))
{
IsSecretFieldValue = bool.Parse(properties["isSecretFieldValue"]);
IsSecretFieldValue = bool.Parse(valueIsSecretValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ internal override IFieldValue FromListDataAsStream(Dictionary<string, string> pr
}
else
{
if (properties.ContainsKey("Label"))
if (properties.TryGetValue("Label", out string valueLabel))
{
Label = properties["Label"];
Label = valueLabel;
}

if (properties.ContainsKey("TermID"))
if (properties.TryGetValue("TermID", out string valueTermId))
{
TermId = Guid.Parse(properties["TermID"]);
TermId = Guid.Parse(valueTermId);
}

WssId = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ internal override IFieldValue FromListDataAsStream(Dictionary<string, string> pr
// first property is the url field
Url = properties.First().Value;

if (properties.ContainsKey("desc"))
if (properties.TryGetValue("desc", out string valueDesc))
{
Description = properties["desc"];
Description = valueDesc;
}

if (!HasValue(nameof(Description)) && HasValue(nameof(Url)))
Expand Down
28 changes: 14 additions & 14 deletions src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUserValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ internal override IFieldValue FromJson(JsonElement json)

internal override IFieldValue FromListDataAsStream(Dictionary<string, string> properties)
{
if (properties.ContainsKey("id"))
if (properties.TryGetValue("id", out string valueId))
{
if (string.IsNullOrEmpty(properties["id"]))
if (string.IsNullOrEmpty(valueId))
{
LookupId = -1;

Expand All @@ -152,35 +152,35 @@ internal override IFieldValue FromListDataAsStream(Dictionary<string, string> pr
return this;
}

LookupId = int.Parse(properties["id"]);
LookupId = int.Parse(valueId);
}

if (properties.ContainsKey("email"))
if (properties.TryGetValue("email", out string valueEmail))
{
Email = properties["email"];
Email = valueEmail;
}

if (properties.ContainsKey("title"))
if (properties.TryGetValue("title", out string valueTitle))
{
Title = properties["title"];
Title = valueTitle;
// when using User fields the value is stored in the title property
LookupValue = properties["title"];
LookupValue = valueTitle;
}

// when using UserMulti fields the value is stored in the value property
if (properties.ContainsKey("value"))
if (properties.TryGetValue("value", out string valueValue))
{
LookupValue = properties["value"];
LookupValue = valueValue;
}

if (properties.ContainsKey("sip"))
if (properties.TryGetValue("sip", out string valueSip))
{
Sip = properties["sip"];
Sip = valueSip;
}

if (properties.ContainsKey("picture"))
if (properties.TryGetValue("picture", out string valuePicture))
{
Picture = properties["picture"];
Picture = valuePicture;
}

// Clear changes
Expand Down

0 comments on commit 9ac6746

Please sign in to comment.