Пример #1
0
        public TObjectType GetValue <TObjectType>()
        {
            TObjectType objValue      = default(TObjectType);
            Type        objObjectType = typeof(TObjectType);

            if (objObjectType.IsEnum == true)
            {
                objValue = (TObjectType)Enum.Parse(objObjectType, Value.ToString());
            }
            else
            {
                SerializedValueType enuValueType = SerializedValueTypeHelper.GetTypeFromSystemType(objObjectType);
                switch (enuValueType)
                {
                case (SerializedValueType.Boolean):
                    objValue = (TObjectType)((object)GetBoolean());
                    break;

                case (SerializedValueType.Byte):
                    objValue = (TObjectType)((object)GetByte());
                    break;

                case (SerializedValueType.Char):
                    objValue = (TObjectType)((object)GetChar());
                    break;

                case (SerializedValueType.DateTime):
                    objValue = (TObjectType)((object)GetDateTime());
                    break;

                case (SerializedValueType.Decimal):
                    objValue = (TObjectType)((object)GetDecimal());
                    break;

                case (SerializedValueType.Double):
                    objValue = (TObjectType)((object)GetDouble());
                    break;

                case (SerializedValueType.Enum):
                    objValue = (TObjectType)Enum.Parse(objObjectType, GetString());
                    break;

                case (SerializedValueType.Guid):
                    objValue = (TObjectType)((object)GetGuid());
                    break;

                case (SerializedValueType.Int16):
                    objValue = (TObjectType)((object)GetInt16());
                    break;

                case (SerializedValueType.Int32):
                    objValue = (TObjectType)((object)GetInt32());
                    break;

                case (SerializedValueType.Int64):
                    objValue = (TObjectType)((object)GetInt64());
                    break;

                case (SerializedValueType.SByte):
                    objValue = (TObjectType)((object)GetSByte());
                    break;

                case (SerializedValueType.Single):
                    objValue = (TObjectType)((object)GetSingle());
                    break;

                case (SerializedValueType.String):
                    objValue = (TObjectType)((object)GetString());
                    break;

                case (SerializedValueType.UInt16):
                    objValue = (TObjectType)((object)GetUInt16());
                    break;

                case (SerializedValueType.UInt32):
                    objValue = (TObjectType)((object)GetUInt32());
                    break;

                case (SerializedValueType.UInt64):
                    objValue = (TObjectType)((object)GetUInt64());
                    break;

                case (SerializedValueType.Timespan):
                    objValue = (TObjectType)((object)GetTimespan());
                    break;

                case (SerializedValueType.ByteArray):
                    objValue = (TObjectType)((object)GetByteArray());
                    break;
                }
            }

            return(objValue);
        }
Пример #2
0
        public SerializedValue Add(string strName, object objValue)
        {
            SerializedValueType enuValueType = SerializedValueTypeHelper.GetTypeFromObject(objValue);

            return(Add(strName, objValue, enuValueType));
        }