コード例 #1
0
        public static TransportableDataType GetTypeFromObject(object objValue)
        {
            TransportableDataType enuValueType = TransportableDataType.Unknown;

            if ((objValue == null) || (objValue is DBNull))
            {
                enuValueType = TransportableDataType.Null;
            }
            else if (objValue is ITransportableObject)
            {
                enuValueType = TransportableDataType.ITransportableObject;
            }
            else
            {
                Type objKey = objValue.GetType();
                if (_objObjectDataTypeMap.ContainsKey(objKey) == true)
                {
                    enuValueType = _objObjectDataTypeMap[objKey];
                }
                else if (objKey.IsSerializable == true)
                {
                    enuValueType = TransportableDataType.Object;
                }
            }

            return(enuValueType);
        }
コード例 #2
0
        public override void WriteData(BinaryWriterExtension objBinaryWriter)
        {
            base.WriteData(objBinaryWriter);

            TransportableDataType enuDataType = TransportableDataTypeHelper.GetTypeFromSystemType(typeof(TObjectType));

            int intCount = this.Count;

            objBinaryWriter.Write(intCount);

            for (int intIndex = 0; intIndex < intCount; intIndex++)
            {
                TObjectType objItem = this[intIndex];
                objBinaryWriter.WriteObject(objItem, enuDataType);
            }
        }
コード例 #3
0
        public static TransportableDataType GetTypeFromSystemType(Type objType)
        {
            TransportableDataType enuValueType = TransportableDataType.Unknown;

            if (objType == null)
            {
                enuValueType = TransportableDataType.Null;
            }
            else
            {
                if (_objObjectDataTypeMap.ContainsKey(objType) == true)
                {
                    enuValueType = _objObjectDataTypeMap[objType];
                }
                else if (objType.IsSerializable == true)
                {
                    enuValueType = TransportableDataType.Object;
                }
            }

            return(enuValueType);
        }
コード例 #4
0
        public void WriteObject(object objObject, TransportableDataType enuTransportableDataType, bool blnIncludeType)
        {
            if (blnIncludeType == true)
            {
                Byte bytEnumValue = Convert.ToByte(enuTransportableDataType);
                base.Write(bytEnumValue);
            }
            switch (enuTransportableDataType)
            {
            case (TransportableDataType.Unknown):
                throw new ArgumentException(string.Format("The argument's type ({0}) is not serializable.", objObject.GetType().FullName));

            case (TransportableDataType.Null):
                break;

            case (TransportableDataType.Boolean):
                Write((bool)objObject);
                break;

            case (TransportableDataType.Byte):
                Write((byte)objObject);
                break;

            case (TransportableDataType.ByteArray):
                WriteByteArray((byte[])objObject);
                break;

            case (TransportableDataType.Char):
                Write((char)objObject);
                break;

            case (TransportableDataType.DateTime):
                WriteDateTime((DateTime)objObject);
                break;

            case (TransportableDataType.Decimal):
                Write((decimal)objObject);
                break;

            case (TransportableDataType.Double):
                Write((double)objObject);
                break;

            case (TransportableDataType.Guid):
                WriteGuid((Guid)objObject);
                break;

            case (TransportableDataType.Enum):
                WriteEnum((Enum)objObject);
                break;

            case (TransportableDataType.Int16):
                Write((Int16)objObject);
                break;

            case (TransportableDataType.Int32):
                Write((Int32)objObject);
                break;

            case (TransportableDataType.Int64):
                Write((Int64)objObject);
                break;

            case (TransportableDataType.ITransportableObject):
                WriteTransportableObject((ITransportableObject)objObject);
                break;

            case (TransportableDataType.SByte):
                Write((sbyte)objObject);
                break;

            case (TransportableDataType.Single):
                Write((Single)objObject);
                break;

            case (TransportableDataType.String):
                Write((string)objObject);
                break;

            case (TransportableDataType.UInt16):
                Write((UInt16)objObject);
                break;

            case (TransportableDataType.UInt32):
                Write((UInt32)objObject);
                break;

            case (TransportableDataType.UInt64):
                Write((UInt64)objObject);
                break;

            case (TransportableDataType.TimeSpan):
                WriteTimeSpan((TimeSpan)objObject);
                break;

            case (TransportableDataType.Object):

                bool blnIsNull = (objObject == null);
                Write(blnIsNull);

                if (blnIsNull == false)
                {
                    using (MemoryStream objMemoryStream = new MemoryStream())
                    {
                        BinaryFormatter objBinaryFormatter = new BinaryFormatter();
                        objBinaryFormatter.Serialize(objMemoryStream, objObject);

                        byte[] bytObjectData = objMemoryStream.ToArray();
                        WriteByteArray(bytObjectData);
                    }
                }
                break;
            }
        }
コード例 #5
0
 public void WriteObject(object objObject, TransportableDataType enuTransportableDataType)
 {
     WriteObject(objObject, enuTransportableDataType, true);
 }
コード例 #6
0
        public void WriteObject(object objObject)
        {
            TransportableDataType enuTransportableDataType = TransportableDataTypeHelper.GetTypeFromObject(objObject);

            WriteObject(objObject, enuTransportableDataType, true);
        }
コード例 #7
0
        public object ReadObject(TransportableDataType enuDataType)
        {
            object objValue = null;

            switch (enuDataType)
            {
            case (TransportableDataType.Null):
                break;

            case (TransportableDataType.Boolean):
                objValue = ReadBoolean();
                break;

            case (TransportableDataType.Byte):
                objValue = ReadByte();
                break;

            case (TransportableDataType.ByteArray):
                objValue = ReadByteArray();
                break;

            case (TransportableDataType.Char):
                objValue = ReadChar();
                break;

            case (TransportableDataType.DateTime):
                objValue = ReadDateTime();
                break;

            case (TransportableDataType.Decimal):
                objValue = ReadDecimal();
                break;

            case (TransportableDataType.Double):
                objValue = ReadDouble();
                break;

            case (TransportableDataType.Guid):
                objValue = ReadGuid();
                break;

            case (TransportableDataType.Enum):
                objValue = ReadInt32();
                break;

            case (TransportableDataType.Int16):
                objValue = ReadInt16();
                break;

            case (TransportableDataType.Int32):
                objValue = ReadInt32();
                break;

            case (TransportableDataType.Int64):
                objValue = ReadInt64();
                break;

            case (TransportableDataType.ITransportableObject):
                objValue = ReadTransportableObject <ITransportableObject>();
                break;

            case (TransportableDataType.SByte):
                objValue = ReadSByte();
                break;

            case (TransportableDataType.Single):
                objValue = ReadSingle();
                break;

            case (TransportableDataType.String):
                objValue = ReadString();
                break;

            case (TransportableDataType.UInt16):
                objValue = ReadUInt16();
                break;

            case (TransportableDataType.UInt32):
                objValue = ReadUInt32();
                break;

            case (TransportableDataType.UInt64):
                objValue = ReadUInt64();
                break;

            case (TransportableDataType.TimeSpan):
                objValue = new TimeSpan(ReadInt64());
                break;

            case (TransportableDataType.Object):

                bool blnIsNull = ReadBoolean();
                if (blnIsNull == false)
                {
                    byte[] bytObjectData = ReadByteArray();
                    using (MemoryStream objMemoryStream = new MemoryStream(bytObjectData))
                    {
                        BinaryFormatter objBinaryFormatter = new BinaryFormatter();
                        objValue = objBinaryFormatter.Deserialize(objMemoryStream);
                    }
                }

                break;
            }

            return(objValue);
        }
コード例 #8
0
        public object ReadObject()
        {
            TransportableDataType enuDataType = (TransportableDataType)ReadByte();

            return(ReadObject(enuDataType));
        }
コード例 #9
0
        public static bool IsTypeSupported(object objValue)
        {
            TransportableDataType enuValueType = GetTypeFromObject(objValue);

            return(enuValueType != TransportableDataType.Unknown);
        }