Skip to content

Commit fb6a5ab

Browse files
author
Jani Giannoudis
committed
fix #1 — replace GetObjectLookup with GetLookupField: fix misleading parameter order (objectKey before lookupKey caused ArgumentException when called with two arguments)
1 parent f050aef commit fb6a5ab

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

Client.Scripting/Function/PayrollFunction.Action.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public ActionValue GetLookupValue(string lookup, ActionValue keyOrRangeValue, st
8787
lookupKey: keyOrRangeValue));
8888
}
8989
// object field lookup value
90-
return new(GetObjectLookup<object>(
90+
return new(GetLookupField<object>(
9191
lookupName: lookup,
9292
lookupKey: keyOrRangeValue,
93-
objectKey: field));
93+
fieldName: field));
9494
}
9595

9696
/// <summary>Get lookup value by key and range value</summary>

Client.Scripting/Function/PayrollFunction.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ public bool HasLookup(string lookupName) =>
991991
/// <returns>The typed lookup value, or <c>default(T)</c> when the key is not found</returns>
992992
/// <remarks>
993993
/// When the stored value is a JSON object and <typeparamref name="T"/> is not <c>string</c>,
994-
/// the JSON is deserialized automatically. Use <see cref="GetObjectLookup{T}(string, string, string, string)"/>
994+
/// the JSON is deserialized automatically. Use <see cref="GetLookupField{T}(string, string, string, string)"/>
995995
/// to extract a single property from a JSON-object lookup value.
996996
/// </remarks>
997997
public T GetLookup<T>(string lookupName, string lookupKey, string culture = null)
@@ -1022,16 +1022,16 @@ public T GetLookup<T>(string lookupName, object[] lookupKeyValues, string cultur
10221022
return GetLookup<T>(lookupName, JsonSerializer.Serialize(lookupKeyValues), culture);
10231023
}
10241024

1025-
/// <summary>Get object lookup by range value</summary>
1025+
/// <summary>Get a single field from a JSON-object lookup entry</summary>
10261026
/// <param name="lookupName">The lookup name</param>
1027-
/// <param name="objectKey">The object key</param>
1028-
/// <param name="lookupKey">The lookup key (optional)</param>
1027+
/// <param name="lookupKey">The exact key to look up</param>
1028+
/// <param name="fieldName">The JSON property name to extract from the object</param>
10291029
/// <param name="culture">The culture, null for the system culture (optional)</param>
1030-
public T GetObjectLookup<T>(string lookupName, string objectKey,
1031-
string lookupKey = null, string culture = null)
1030+
/// <returns>The typed field value, or <c>default(T)</c> when the lookup, key, or field is not found</returns>
1031+
public T GetLookupField<T>(string lookupName, string lookupKey, string fieldName, string culture = null)
10321032
{
10331033
var value = GetLookup<string>(lookupName, lookupKey, culture);
1034-
return string.IsNullOrWhiteSpace(value) ? default : value.ObjectValueJson<T>(objectKey);
1034+
return string.IsNullOrWhiteSpace(value) ? default : value.ObjectValueJson<T>(fieldName);
10351035
}
10361036

10371037
/// <summary>Get payroll lookup range brackets</summary>

Client.Scripting/PayrollEngine.Client.Scripting.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6352,7 +6352,7 @@
63526352
<returns>The typed lookup value, or <c>default(T)</c> when the key is not found</returns>
63536353
<remarks>
63546354
When the stored value is a JSON object and <typeparamref name="T"/> is not <c>string</c>,
6355-
the JSON is deserialized automatically. Use <see cref="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetObjectLookup``1(System.String,System.String,System.String,System.String)"/>
6355+
the JSON is deserialized automatically. Use <see cref="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupField``1(System.String,System.String,System.String,System.String)"/>
63566356
to extract a single property from a JSON-object lookup value.
63576357
</remarks>
63586358
</member>
@@ -6362,12 +6362,13 @@
63626362
<param name="lookupKeyValues">The lookup key values (serialized to JSON string)</param>
63636363
<param name="culture">The culture, null for the system culture (optional)</param>
63646364
</member>
6365-
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetObjectLookup``1(System.String,System.String,System.String,System.String)">
6366-
<summary>Get object lookup by range value</summary>
6365+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupField``1(System.String,System.String,System.String,System.String)">
6366+
<summary>Get a single field from a JSON-object lookup entry</summary>
63676367
<param name="lookupName">The lookup name</param>
6368-
<param name="objectKey">The object key</param>
6369-
<param name="lookupKey">The lookup key (optional)</param>
6368+
<param name="lookupKey">The exact key to look up</param>
6369+
<param name="fieldName">The JSON property name to extract from the object</param>
63706370
<param name="culture">The culture, null for the system culture (optional)</param>
6371+
<returns>The typed field value, or <c>default(T)</c> when the lookup, key, or field is not found</returns>
63716372
</member>
63726373
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupRanges(System.String,System.Nullable{System.Decimal})">
63736374
<summary>Get payroll lookup range brackets</summary>

0 commit comments

Comments
 (0)