Skip to content

Commit adfe5ae

Browse files
authored
Enhance Generic Singular HashFactory with config profile methods
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 2bf8fc4 commit adfe5ae

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

HashifyNet/Core/Factory/HashFactory.GenericSingular.Extensions.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// *
1+
// *
22
// *****************************************************************************
33
// *
44
// * Copyright (c) 2025 Deskasoft International
@@ -27,6 +27,9 @@
2727
// ******************************************************************************
2828
// *
2929

30+
using System;
31+
using System.Collections.Generic;
32+
3033
namespace HashifyNet
3134
{
3235
public sealed partial class HashFactory<TAlgorithmInterface>
@@ -49,5 +52,41 @@ public static TAlgorithmInterface Create(IHashConfigBase config)
4952
{
5053
return Singleton.CreateInstance(config);
5154
}
55+
56+
/// <summary>
57+
/// Retrieves the configuration profiles associated with <typeparamref name="TAlgorithmInterface"/> algorithm.
58+
/// </summary>
59+
/// <returns>An array of <see cref="IHashConfigProfile"/> objects associated with <typeparamref name="TAlgorithmInterface"/> algorithm, or an empty array
60+
/// if no configuration profiles are found for the specified type.</returns>
61+
public static IHashConfigProfile[] GetConfigProfiles()
62+
{
63+
return HashFactory.GetConfigProfiles(typeof(TAlgorithmInterface));
64+
}
65+
66+
/// <summary>
67+
/// Creates a default concrete configuration instance for <typeparamref name="TAlgorithmInterface"/> algorithm.
68+
/// </summary>
69+
/// <returns>An instance of <typeparamref name="TAlgorithmInterface"/> representing the default configuration for <typeparamref name="TAlgorithmInterface"/> algorithm.</returns>
70+
/// <exception cref="KeyNotFoundException">Thrown if no implementation is registered for <typeparamref name="TAlgorithmInterface"/> algorithm.</exception>
71+
/// <exception cref="NotSupportedException">Thrown if no default configuration is available for <typeparamref name="TAlgorithmInterface"/> algorithm.</exception>
72+
public static IHashConfigBase CreateDefaultConcreteConfig()
73+
{
74+
return HashFactory.CreateDefaultConcreteConfig(typeof(TAlgorithmInterface));
75+
}
76+
77+
/// <summary>
78+
/// Attempts to create a default concrete configuration for <typeparamref name="TAlgorithmInterface"/> algorithm.
79+
/// </summary>
80+
/// <remarks>This method catches and handles <see cref="NotSupportedException"/> and <see
81+
/// cref="KeyNotFoundException"/> internally, returning <see langword="false"/> in such cases. Other exceptions may
82+
/// propagate to the caller.</remarks>
83+
/// <param name="config">When this method returns, contains the created configuration if the operation succeeds; otherwise, <see
84+
/// langword="null"/>. This parameter is passed uninitialized.</param>
85+
/// <returns><see langword="true"/> if the default concrete configuration was successfully created; otherwise, <see
86+
/// langword="false"/>.</returns>
87+
public static bool TryCreateDefaultConcreteConfig(out IHashConfigBase config)
88+
{
89+
return HashFactory.TryCreateDefaultConcreteConfig(typeof(TAlgorithmInterface), out config);
90+
}
5291
}
5392
}

0 commit comments

Comments
 (0)