This repository has been archived by the owner on May 25, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
looking at implicit conversions of most common mapping types for asci…
…i, utf8, long, bytes, lexicaluuid and timeuuid, make the column family more durrable
- Loading branch information
Nick Berardi
committed
Apr 27, 2010
1 parent
12cd243
commit 309fe13
Showing
13 changed files
with
377 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.ComponentModel; | ||
|
||
namespace FluentCassandra.Types | ||
{ | ||
public class AsciiType : CassandraType | ||
{ | ||
public override TypeConverter TypeConverter | ||
{ | ||
get { return new StringConverter(); } | ||
} | ||
|
||
public string GetObject(byte[] bytes) | ||
{ | ||
return GetObject<string>(bytes); | ||
} | ||
|
||
public override object GetObject(byte[] bytes, Type type) | ||
{ | ||
var converter = this.TypeConverter; | ||
|
||
if (!converter.CanConvertTo(type)) | ||
throw new NotSupportedException(type + " is not supported for string serialization."); | ||
|
||
return converter.ConvertTo(bytes, type); | ||
} | ||
|
||
public override byte[] GetBytes(object obj) | ||
{ | ||
var converter = this.TypeConverter; | ||
|
||
if (!converter.CanConvertFrom(obj.GetType())) | ||
throw new NotSupportedException(obj.GetType() + " is not supported for string serialization."); | ||
|
||
return (byte[])converter.ConvertFrom(obj); | ||
} | ||
|
||
private string _value; | ||
|
||
public static implicit operator byte[](AsciiType type) | ||
{ | ||
return type.GetBytes(type._value); | ||
} | ||
|
||
public static implicit operator string(AsciiType type) | ||
{ | ||
return type._value; | ||
} | ||
|
||
public static implicit operator AsciiType(byte o) { return Convert(o); } | ||
public static implicit operator AsciiType(sbyte o) { return Convert(o); } | ||
public static implicit operator AsciiType(short o) { return Convert(o); } | ||
public static implicit operator AsciiType(ushort o) { return Convert(o); } | ||
public static implicit operator AsciiType(int o) { return Convert(o); } | ||
public static implicit operator AsciiType(uint o) { return Convert(o); } | ||
public static implicit operator AsciiType(long o) { return Convert(o); } | ||
public static implicit operator AsciiType(ulong o) { return Convert(o); } | ||
public static implicit operator AsciiType(float o) { return Convert(o); } | ||
public static implicit operator AsciiType(double o) { return Convert(o); } | ||
public static implicit operator AsciiType(decimal o) { return Convert(o); } | ||
public static implicit operator AsciiType(bool o) { return Convert(o); } | ||
public static implicit operator AsciiType(string o) { return Convert(o); } | ||
public static implicit operator AsciiType(char o) { return Convert(o); } | ||
public static implicit operator AsciiType(Guid o) { return Convert(o); } | ||
public static implicit operator AsciiType(DateTime o) { return Convert(o); } | ||
public static implicit operator AsciiType(DateTimeOffset o) { return Convert(o); } | ||
|
||
private static AsciiType Convert(object o) | ||
{ | ||
var type = new AsciiType(); | ||
type._value = o.ToString(); | ||
|
||
return type; | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.ComponentModel; | ||
|
||
namespace FluentCassandra.Types | ||
{ | ||
public class BytesType : CassandraType | ||
{ | ||
public override TypeConverter TypeConverter | ||
{ | ||
get { return new BinaryConverter(); } | ||
} | ||
|
||
public byte[] GetObject(byte[] bytes) | ||
{ | ||
return bytes; | ||
} | ||
|
||
public override object GetObject(byte[] bytes, Type type) | ||
{ | ||
var converter = this.TypeConverter; | ||
|
||
if (!converter.CanConvertTo(type)) | ||
throw new NotSupportedException(type + " is not supported for binary serialization."); | ||
|
||
return converter.ConvertTo(bytes, type); | ||
} | ||
|
||
public override byte[] GetBytes(object obj) | ||
{ | ||
var converter = this.TypeConverter; | ||
|
||
if (!converter.CanConvertFrom(obj.GetType())) | ||
throw new NotSupportedException(obj.GetType() + " is not supported for binary serialization."); | ||
|
||
return (byte[])converter.ConvertFrom(obj); | ||
} | ||
|
||
private byte[] _value; | ||
|
||
public static implicit operator byte[](BytesType type) | ||
{ | ||
return type._value; | ||
} | ||
|
||
public static implicit operator BytesType(byte[] s) | ||
{ | ||
return new BytesType { _value = s }; | ||
} | ||
|
||
public static implicit operator BytesType(byte o) { return Convert(o); } | ||
public static implicit operator BytesType(sbyte o) { return Convert(o); } | ||
public static implicit operator BytesType(short o) { return Convert(o); } | ||
public static implicit operator BytesType(ushort o) { return Convert(o); } | ||
public static implicit operator BytesType(int o) { return Convert(o); } | ||
public static implicit operator BytesType(uint o) { return Convert(o); } | ||
public static implicit operator BytesType(long o) { return Convert(o); } | ||
public static implicit operator BytesType(ulong o) { return Convert(o); } | ||
public static implicit operator BytesType(float o) { return Convert(o); } | ||
public static implicit operator BytesType(double o) { return Convert(o); } | ||
public static implicit operator BytesType(decimal o) { return Convert(o); } | ||
public static implicit operator BytesType(bool o) { return Convert(o); } | ||
public static implicit operator BytesType(string o) { return Convert(o); } | ||
public static implicit operator BytesType(char o) { return Convert(o); } | ||
public static implicit operator BytesType(Guid o) { return Convert(o); } | ||
public static implicit operator BytesType(DateTime o) { return Convert(o); } | ||
public static implicit operator BytesType(DateTimeOffset o) { return Convert(o); } | ||
|
||
private static BytesType Convert(object o) | ||
{ | ||
var type = new BytesType(); | ||
type._value = type.GetBytes(o); | ||
|
||
return type; | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.