コード例 #1
0
        /// <summary>
        /// The GetBytes.
        /// </summary>
        /// <param name="objvalue">The objvalue<see cref="Object"/>.</param>
        /// <param name="forKeys">The forKeys<see cref="bool"/>.</param>
        /// <returns>The <see cref="Byte[]"/>.</returns>
        public unsafe static Byte[] GetBytes(this Object objvalue, bool forKeys = false)
        {
            Type t = objvalue.GetType();

            if (objvalue is IUnique)
            {
                if (forKeys)
                {
                    return(((IUnique)objvalue).GetUniqueBytes());
                }
                return(((IUnique)objvalue).GetBytes());
            }

            if (objvalue is IList)
            {
                return(((IList)objvalue).GetBytes(forKeys));
            }

            if (t.IsValueType)
            {
                if (t.IsPrimitive)
                {
                    return(Extraction.ValueStructureToBytes(objvalue));
                }
                if (objvalue is DateTime)
                {
                    return(((DateTime)objvalue).ToBinary().GetBytes());
                }
                if (objvalue is Enum)
                {
                    return(Convert.ToInt32(objvalue).GetBytes());
                }
                return(objvalue.GetStructureBytes());
            }

            if (t.IsLayoutSequential)
            {
                return(objvalue.GetSequentialBytes());
            }

            if (objvalue is String || objvalue is IFormattable)
            {
                return(((string)objvalue).GetBytes());
            }

            return(new byte[0]);
        }
コード例 #2
0
 /// <summary>
 /// The GetValueStructureBytes.
 /// </summary>
 /// <param name="structure">The structure<see cref="object"/>.</param>
 /// <returns>The <see cref="byte[]"/>.</returns>
 public unsafe static byte[] GetValueStructureBytes(this object structure)
 {
     return(Extraction.ValueStructureToBytes(structure));
 }