我正在用System.Security.Cryptography编写自己的包装程序,以为那些与Crypto相关的调用提供直观且易于使用的工具。我想知道是否应该为所有原始类型编写很多重载方法,还是只为System.Object类型编写?
我尝试了前一种方法,为这些类型编写了很多冗余代码。但是事实证明这很痛苦!我也考虑过接口,但是它仅适用于(新)自定义类型,对吗?
这是我的代码的示例部分:
public static class CryptographyService
{
/// <summary>
/// Compute hash of a System.Byte[] object.
/// </summary>
/// <param name="s">Byte array to be hashed.</param>
public static string ComputeHash(byte[] byteArray)
{
}
/// <summary>
/// Compute hash of a System.Int32 object.
/// </summary>
/// <param name="s">Integer to be hashed.</param>
public static string ComputeHash(int i)
{
}
/// <summary>
/// Compute hash of a System.Char object.
/// </summary>
/// <param name="s">Char to be hashed.</param>
public static string ComputeHash(char c)
{
}
/// <summary>
/// Compute hash of a System.Int16 object.
/// </summary>
/// <param name="s">Short integer to be hashed.</param>
public static string ComputeHash(short s)
{
}
}
我想了解经验丰富的开发人员的见解,“这是一个好习惯吗?”。谢谢!