Esempio n. 1
0
        public static Int32 GetValueTypeHashKey32(object obj)
        {
            if (obj is IUnique)
            {
                return(((IUnique)obj).GetKeyBytes().BitAggregate64to32().ToInt32());
            }

            if (obj.GetType().IsPrimitive)
            {
                byte *ps = stackalloc byte[8];
                Marshal.StructureToPtr(obj, (IntPtr)ps, false);
                return(BitAggregate64to32(ps));
            }

            if (obj is DateTime)
            {
                return(((DateTime)obj).ToBinary().GetBytes().BitAggregate64to32().ToInt32());
            }
            if (obj is Enum)
            {
                return(Convert.ToInt32(obj));
            }

            if (obj.GetType().IsLayoutSequential)
            {
                byte *ps = stackalloc byte[8];
                ExtractOperation.ValueStructureToPointer(obj, ps, 0);
                return(BitAggregate64to32(ps));
            }


            return((int)HashHandle32.ComputeHashCode(obj.GetBytes()));
        }
Esempio n. 2
0
        public static Int64 GetValueTypeHashKey64(object obj)
        {
            if (obj is IUnique)
            {
                return(((IUnique)obj).KeyBlock);
            }

            Type t = obj.GetType();

            if (t.IsPrimitive)
            {
                byte *ps = stackalloc byte[8];
                Marshal.StructureToPtr(obj, (IntPtr)ps, false);
                return(*(long *)ps);
            }

            if (obj is DateTime)
            {
                return(((DateTime)obj).ToBinary());
            }
            if (obj is Enum)
            {
                return(Convert.ToInt32(obj));
            }

            if (t.IsLayoutSequential)
            {
                byte *ps = stackalloc byte[8];
                ExtractOperation.ValueStructureToPointer(obj, ps, 0);
                return(*(long *)ps);
            }


            return((long)HashHandle64.ComputeHashCode(obj.GetBytes()));
        }
Esempio n. 3
0
        public static Byte[] GetValueTypeHashBytes64(object obj)
        {
            if (obj is IUnique)
            {
                return(((IUnique)obj).GetKeyBytes());
            }

            if (obj.GetType().IsPrimitive)
            {
                byte[] s = new byte[8];
                fixed(byte *ps = s)
                {
                    Marshal.StructureToPtr(obj, (IntPtr)ps, false);
                    return(s);
                }
            }

            if (obj is DateTime)
            {
                return(((DateTime)obj).ToBinary().GetBytes());
            }
            if (obj is Enum)
            {
                return(Convert.ToInt32(obj).GetBytes());
            }

            if (obj.GetType().IsLayoutSequential)
            {
                byte[] s = new byte[8];
                fixed(byte *ps = s)
                {
                    ExtractOperation.ValueStructureToPointer(obj, ps, 0);
                    return(s);
                }
            }

            return(((long)HashHandle64.ComputeHashCode(obj.GetBytes())).GetBytes());
        }