コード例 #1
0
        public static async Task <string> GetHashAsync <T>([DisallowNull] T item) where T : class
        {
            using SHA256 sha256Obj = SHA256.Create();
            byte[] result = sha256Obj.ComputeHash(await SerializeUtil.PackAsync(item).ConfigureAwait(false));

            return(Convert.ToBase64String(result));
        }
コード例 #2
0
        static ValueConverterUtil()
        {
            #region type to type

            _convertFunDict[typeof(byte)]           = o => { return(Convert.ToByte(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(sbyte)]          = o => { return(Convert.ToSByte(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(short)]          = o => { return(Convert.ToInt16(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(ushort)]         = o => { return(Convert.ToUInt16(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(int)]            = o => { return(Convert.ToInt32(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(uint)]           = o => { return(Convert.ToUInt32(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(long)]           = o => { return(Convert.ToInt64(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(ulong)]          = o => { return(Convert.ToUInt64(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(float)]          = o => { return(Convert.ToSingle(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(double)]         = o => { return(Convert.ToDouble(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(decimal)]        = o => { return(Convert.ToDecimal(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(bool)]           = o => { return(Convert.ToBoolean(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(string)]         = o => { return(Convert.ToString(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(char)]           = o => { return(Convert.ToChar(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(Guid)]           = o => { return(Guid.Parse(o.ToString())); };
            _convertFunDict[typeof(DateTime)]       = o => { return(DateTime.Parse(o.ToString(), GlobalSettings.Culture)); };
            _convertFunDict[typeof(DateTimeOffset)] = o => { return((DateTimeOffset)DateTime.SpecifyKind(DateTime.Parse(o.ToString(), GlobalSettings.Culture), DateTimeKind.Utc)); };
            _convertFunDict[typeof(TimeSpan)]       = o => { return(Convert.ToDateTime(o, GlobalSettings.Culture)); };

            _convertFunDict[typeof(byte?)]           = o => { return(Convert.ToByte(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(sbyte?)]          = o => { return(Convert.ToSByte(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(short?)]          = o => { return(Convert.ToInt16(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(ushort?)]         = o => { return(Convert.ToUInt16(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(int?)]            = o => { return(Convert.ToInt32(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(uint?)]           = o => { return(Convert.ToUInt32(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(long?)]           = o => { return(Convert.ToInt64(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(ulong?)]          = o => { return(Convert.ToUInt64(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(float?)]          = o => { return(Convert.ToSingle(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(double?)]         = o => { return(Convert.ToDouble(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(decimal?)]        = o => { return(Convert.ToDecimal(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(bool?)]           = o => { return(Convert.ToBoolean(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(char?)]           = o => { return(Convert.ToChar(o, GlobalSettings.Culture)); };
            _convertFunDict[typeof(Guid?)]           = o => { return(Guid.Parse(o.ToString())); };
            _convertFunDict[typeof(DateTime?)]       = o => { return(o == null ? null : new DateTime?(DateTime.Parse(o.ToString(), GlobalSettings.Culture))); };
            _convertFunDict[typeof(DateTimeOffset?)] = o => { return((DateTimeOffset)DateTime.SpecifyKind(DateTime.Parse(o.ToString(), GlobalSettings.Culture), DateTimeKind.Utc)); };
            _convertFunDict[typeof(TimeSpan?)]       = o => { return(Convert.ToDateTime(o, GlobalSettings.Culture)); };

            _convertFunDict[typeof(byte[])] = o => { return(SerializeUtil.PackAsync(o)); };
            _convertFunDict[typeof(object)] = o => { return(o ?? null); };
            _convertFunDict[typeof(DBNull)] = o => { return(DBNull.Value); };

            #endregion
        }