This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
BooleanType.cs
98 lines (74 loc) · 1.79 KB
/
BooleanType.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
namespace FluentCassandra.Types
{
public class BooleanType : CassandraObject
{
private static readonly BooleanTypeConverter Converter = new BooleanTypeConverter();
#region Implimentation
protected override object GetValueInternal(Type type)
{
return Converter.ConvertTo(_value, type);
}
public override void SetValue(object obj)
{
_value = Converter.ConvertFrom(obj);
}
public override byte[] ToBigEndian()
{
return Converter.ToBigEndian(_value);
}
public override void SetValueFromBigEndian(byte[] value)
{
_value = Converter.FromBigEndian(value);
}
protected override TypeCode TypeCode
{
get { return TypeCode.Boolean; }
}
public override string ToString()
{
return _value.ToString();
}
#endregion
protected override object GetRawValue() { return _value; }
private bool _value;
#region Equality
public override bool Equals(object obj)
{
if (obj is BooleanType)
return _value == ((BooleanType)obj)._value;
return _value == Converter.ConvertFrom(obj);
}
public override int GetHashCode()
{
return _value.GetHashCode();
}
#endregion
#region Conversion
public static implicit operator bool(BooleanType type)
{
return type._value;
}
public static implicit operator BooleanType(bool o)
{
return new BooleanType {
_value = o
};
}
public static implicit operator BooleanType(byte[] o) { return ConvertFrom(o); }
public static implicit operator byte[](BooleanType o) { return ConvertTo<byte[]>(o); }
private static T ConvertTo<T>(BooleanType type)
{
if (type == null)
return default(T);
return type.GetValue<T>();
}
private static BooleanType ConvertFrom(object o)
{
var type = new BooleanType();
type.SetValue(o);
return type;
}
#endregion
}
}