Add SignatureDtoExtensions with Convert<T> method
Introduce a new static class `SignatureDtoExtensions` that adds a `Convert<T>` extension method for collections of `SignatureDto` objects. This method converts all `SignatureDto` instances in a collection to a specified `UnitOfLength`, modifying them in place and returning the same collection. The method includes: - A generic constraint to support any `IEnumerable<SignatureDto>`. - Null checks to ensure the collection is not null. - Comprehensive XML documentation with usage examples and notes.
This commit is contained in:
@@ -65,4 +65,37 @@ public class SignatureDto
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SignatureDtoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts all signatures in the collection to the specified unit of length.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the collection (IEnumerable, List, etc.)</typeparam>
|
||||
/// <param name="signatures">Collection of SignatureDto objects to convert.</param>
|
||||
/// <param name="unitOfLength">Target unit of measurement (Inch or Point).</param>
|
||||
/// <returns>The same collection with all signatures converted to the specified unit.</returns>
|
||||
/// <exception cref="ArgumentNullException">Thrown when signatures collection is null.</exception>
|
||||
/// <remarks>
|
||||
/// <b>Usage:</b>
|
||||
/// <code>
|
||||
/// var signatures = await SignatureService.GetAsync(envelopeKey);
|
||||
/// var convertedSignatures = signatures.ConvertAll(UnitOfLength.Point);
|
||||
/// </code>
|
||||
/// <b>Note:</b> This method modifies each SignatureDto object in place and returns the same collection.
|
||||
/// </remarks>
|
||||
public static T Convert<T>(this T signatures, UnitOfLength unitOfLength)
|
||||
where T : IEnumerable<SignatureDto>
|
||||
{
|
||||
if (signatures == null)
|
||||
throw new ArgumentNullException(nameof(signatures));
|
||||
|
||||
foreach (var signature in signatures)
|
||||
{
|
||||
signature.Convert(unitOfLength);
|
||||
}
|
||||
|
||||
return signatures;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user