Skip to content

Commit 9ac6746

Browse files
committed
performance optimizations
1 parent 126b224 commit 9ac6746

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldLookupValue.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal override IFieldValue FromJson(JsonElement json)
101101

102102
internal override IFieldValue FromListDataAsStream(Dictionary<string, string> properties)
103103
{
104-
if (!properties.ContainsKey("lookupId"))
104+
if (!properties.TryGetValue("lookupId", out string value))
105105
{
106106
LookupId = -1;
107107
IsSecretFieldValue = false;
@@ -118,19 +118,16 @@ internal override IFieldValue FromListDataAsStream(Dictionary<string, string> pr
118118
}
119119
else
120120
{
121-
if (properties.ContainsKey("lookupId"))
122-
{
123-
LookupId = int.Parse(properties["lookupId"]);
124-
}
121+
LookupId = int.Parse(value);
125122

126-
if (properties.ContainsKey("lookupValue"))
123+
if (properties.TryGetValue("lookupValue", out string valueLookupValue))
127124
{
128-
LookupValue = properties["lookupValue"];
125+
LookupValue = valueLookupValue;
129126
}
130127

131-
if (properties.ContainsKey("isSecretFieldValue"))
128+
if (properties.TryGetValue("isSecretFieldValue", out string valueIsSecretValue))
132129
{
133-
IsSecretFieldValue = bool.Parse(properties["isSecretFieldValue"]);
130+
IsSecretFieldValue = bool.Parse(valueIsSecretValue);
134131
}
135132
}
136133

src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldTaxonomyValue.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ internal override IFieldValue FromListDataAsStream(Dictionary<string, string> pr
116116
}
117117
else
118118
{
119-
if (properties.ContainsKey("Label"))
119+
if (properties.TryGetValue("Label", out string valueLabel))
120120
{
121-
Label = properties["Label"];
121+
Label = valueLabel;
122122
}
123123

124-
if (properties.ContainsKey("TermID"))
124+
if (properties.TryGetValue("TermID", out string valueTermId))
125125
{
126-
TermId = Guid.Parse(properties["TermID"]);
126+
TermId = Guid.Parse(valueTermId);
127127
}
128128

129129
WssId = -1;

src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUrlValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ internal override IFieldValue FromListDataAsStream(Dictionary<string, string> pr
102102
// first property is the url field
103103
Url = properties.First().Value;
104104

105-
if (properties.ContainsKey("desc"))
105+
if (properties.TryGetValue("desc", out string valueDesc))
106106
{
107-
Description = properties["desc"];
107+
Description = valueDesc;
108108
}
109109

110110
if (!HasValue(nameof(Description)) && HasValue(nameof(Url)))

src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FieldUserValue.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ internal override IFieldValue FromJson(JsonElement json)
140140

141141
internal override IFieldValue FromListDataAsStream(Dictionary<string, string> properties)
142142
{
143-
if (properties.ContainsKey("id"))
143+
if (properties.TryGetValue("id", out string valueId))
144144
{
145-
if (string.IsNullOrEmpty(properties["id"]))
145+
if (string.IsNullOrEmpty(valueId))
146146
{
147147
LookupId = -1;
148148

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

155-
LookupId = int.Parse(properties["id"]);
155+
LookupId = int.Parse(valueId);
156156
}
157157

158-
if (properties.ContainsKey("email"))
158+
if (properties.TryGetValue("email", out string valueEmail))
159159
{
160-
Email = properties["email"];
160+
Email = valueEmail;
161161
}
162162

163-
if (properties.ContainsKey("title"))
163+
if (properties.TryGetValue("title", out string valueTitle))
164164
{
165-
Title = properties["title"];
165+
Title = valueTitle;
166166
// when using User fields the value is stored in the title property
167-
LookupValue = properties["title"];
167+
LookupValue = valueTitle;
168168
}
169169

170170
// when using UserMulti fields the value is stored in the value property
171-
if (properties.ContainsKey("value"))
171+
if (properties.TryGetValue("value", out string valueValue))
172172
{
173-
LookupValue = properties["value"];
173+
LookupValue = valueValue;
174174
}
175175

176-
if (properties.ContainsKey("sip"))
176+
if (properties.TryGetValue("sip", out string valueSip))
177177
{
178-
Sip = properties["sip"];
178+
Sip = valueSip;
179179
}
180180

181-
if (properties.ContainsKey("picture"))
181+
if (properties.TryGetValue("picture", out string valuePicture))
182182
{
183-
Picture = properties["picture"];
183+
Picture = valuePicture;
184184
}
185185

186186
// Clear changes

0 commit comments

Comments
 (0)