예제 #1
0
파일: HmSerializer.cs 프로젝트: flwn/HmLib
        private void SerializeSimpleValue(IObjectBuilder builder, object value)
        {
            if (value == null)
            {
                throw new InvalidOperationException("Cannot write null value. Use empty string for void values.");
            }

            var stringValue = value as string;

            if (stringValue != null)
            {
                builder.WriteStringValue(stringValue);
                return;
            }

            if (value is int)
            {
                builder.WriteInt32Value((int)value);
                return;
            }

            if (value is bool)
            {
                builder.WriteBooleanValue((bool)value);
                return;
            }

            if (value is double)
            {
                builder.WriteDoubleValue((double)value);
                return;
            }

            throw new InvalidOperationException("Type not supported");
        }
예제 #2
0
        private void ConvertValue(IMessageReader reader, IObjectBuilder builder)
        {
            switch (reader.ValueType)
            {
            case ContentType.Array:
                ConvertArrayContent(reader, builder);
                break;

            case ContentType.Struct:
                ConvertStructContent(reader, builder);
                break;

            case ContentType.Int:
                builder.WriteInt32Value(reader.IntValue);
                break;

            case ContentType.Boolean:
                builder.WriteBooleanValue(reader.BooleanValue);
                break;

            case ContentType.String:
                builder.WriteStringValue(reader.StringValue);
                break;

            case ContentType.Float:
                builder.WriteDoubleValue(reader.DoubleValue);
                break;

            case ContentType.Base64:
                builder.WriteBase64String(reader.StringValue);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #3
0
 private void ConvertValue(IMessageReader reader, IObjectBuilder builder)
 {
     switch (reader.ValueType)
     {
         case ContentType.Array:
             ConvertArrayContent(reader, builder);
             break;
         case ContentType.Struct:
             ConvertStructContent(reader, builder);
             break;
         case ContentType.Int:
             builder.WriteInt32Value(reader.IntValue);
             break;
         case ContentType.Boolean:
             builder.WriteBooleanValue(reader.BooleanValue);
             break;
         case ContentType.String:
             builder.WriteStringValue(reader.StringValue);
             break;
         case ContentType.Float:
             builder.WriteDoubleValue(reader.DoubleValue);
             break;
         case ContentType.Base64:
             builder.WriteBase64String(reader.StringValue);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }