diff --git a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldLookupValue.cs b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldLookupValue.cs index ef17177ec4..5166b4bf01 100644 --- a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldLookupValue.cs +++ b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldLookupValue.cs @@ -101,7 +101,7 @@ internal override IFieldValue FromJson(JsonElement json) internal override IFieldValue FromListDataAsStream(Dictionary properties) { - if (!properties.ContainsKey("lookupId")) + if (!properties.TryGetValue("lookupId", out string value)) { LookupId = -1; IsSecretFieldValue = false; @@ -118,19 +118,16 @@ internal override IFieldValue FromListDataAsStream(Dictionary 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); } } diff --git a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldTaxonomyValue.cs b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldTaxonomyValue.cs index d24a2afdab..8e38f0bea7 100644 --- a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldTaxonomyValue.cs +++ b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldTaxonomyValue.cs @@ -116,14 +116,14 @@ internal override IFieldValue FromListDataAsStream(Dictionary 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; diff --git a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUrlValue.cs b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUrlValue.cs index dda8fe0a09..d44e383af4 100644 --- a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUrlValue.cs +++ b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUrlValue.cs @@ -102,9 +102,9 @@ internal override IFieldValue FromListDataAsStream(Dictionary 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))) diff --git a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUserValue.cs b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUserValue.cs index a7947e306b..83e430a982 100644 --- a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUserValue.cs +++ b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUserValue.cs @@ -140,9 +140,9 @@ internal override IFieldValue FromJson(JsonElement json) internal override IFieldValue FromListDataAsStream(Dictionary properties) { - if (properties.ContainsKey("id")) + if (properties.TryGetValue("id", out string valueId)) { - if (string.IsNullOrEmpty(properties["id"])) + if (string.IsNullOrEmpty(valueId)) { LookupId = -1; @@ -152,35 +152,35 @@ internal override IFieldValue FromListDataAsStream(Dictionary 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