Net.Bluewalk.DotNetUtils/Extensions/ObjectExtensions.cs
/// <summary>
/// Private function to compute hash of provided cryptoServiceProvider
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="instance"></param>
/// <param name="cryptoServiceProvider"></param>
/// <returns></returns>
Private function to compute hash of provided cryptoServiceProvider
Private function to compute hash of provided cryptoServiceProvider
private static string ComputeHash<T>(object instance, T cryptoServiceProvider) where T : HashAlgorithm, new()
        {
            var serializer = new DataContractSerializer(instance.GetType());
            using var memoryStream = new MemoryStream();
            serializer.WriteObject(memoryStream, instance);
            cryptoServiceProvider.ComputeHash(memoryStream.ToArray());
            return cryptoServiceProvider.Hash.Aggregate(string.Empty, (current, t) => current + t.ToString("X2"));
        }
private static string ComputeHash < T > ( object instance , T cryptoServiceProvider ) where T : HashAlgorithm , new ( ) { var serializer = new DataContractSerializer ( instance . GetType ( ) ) ; using var memoryStream = new MemoryStream ( ) ; serializer . WriteObject ( memoryStream , instance ) ; cryptoServiceProvider . ComputeHash ( memoryStream . ToArray ( ) ) ; return cryptoServiceProvider . Hash . Aggregate ( string . Empty , ( current , t ) => current + t . ToString ( " " ) ) ; }
Private function to compute hash of provided cryptoServiceProvider
Private function to compute hash of provided cryptoServiceProvider
None
instance
object
None
cryptoServiceProvider
T
None
typeparam
None