The method HasInvalidInputs
accepts the tuple with keys and values, herewith the number of pairs, and also keys names are unknown at advance.
public class ValidatableControlsGroup
{
public static bool HasInvalidInputs(object /* TODO specify more exact type */ controlsPayload)
{
// TODO implement
return true;
}
}
If it was the TypeScript, in above code it will be { [key: string]: ValidatableControl.Payload }
instead of object
. The usage of ValidatableControlsGroup.Payload
could be:
public partial class TaskManager : ComponentBase
{
private (ValidatableControl.Payload taskTitle, ValidatableControl.Payload taskDescription) controlsPayload = (
taskTitle: new ValidatableControl.Payload(initialValue: "", new TaskTitleInputtedDataValidation()),
taskDescription: new ValidatableControl.Payload(initialValue: "", new TaskTitleInputtedDataValidation())
);
private void updateTask()
{
if (ValidatableControlsGroup.HasInvalidInputs(this.controlsPayload))
{
ValidatableControlsGroup.PointOutValidationErrors(this.controlsPayload);
return;
}
this.targetTask.Title = this.controlsPayload.taskTitle.GetExpectedToBeValidValue();
this.targetTask.Description = this.controlsPayload.taskDescription.GetExpectedToBeValidValue();
// ...
}
}
Inside TaskManager
we need to access to each ValidatableControl.Payload
by key that is why I want to use the tuple with keys.
If it was the TypeScript, the type of controlsPayload
was { taskTitle: ValidatableControl.Payload; taskDescription: ValidatableControl.Payload }
which is compatible with generalized { [key: string]: ValidatableControl.Payload }
of parameter of ValidatableControlsGroup.HasInvalidInputs
.
Please note that the enumerating like if (ValidatableControlsGroup.HasInvalidInputs(item1, item2, item3, item4))
is not allowed because the ValidatableControlsGroup
is being developed as library class thus it take care about routines like extraction of the elements from the tuple.
Lastly, in my case the HasInvalidInputs
method needs only values, but not keys.
However, if the transforming to array required, the HasInvalidInputs
as the library class must take care about this routine.
Regarding my case HasInvalidInputs
method does not need the keys - it is enough the values.
However, the keys are required in TaskManager
. If will set the types of controlsPayload
parameter to ValidatableControl.Payload[]
, the library user will be forced to transform the tuple to array that is unacceptable for library class because the library class must take care about such routines.