18 using System.Collections.Generic;
19 using System.Globalization;
21 namespace Deveel.Data.Serialization {
23 private readonly Dictionary<string, object>
values;
25 internal ObjectData(Type entityType, IEnumerable<KeyValuePair<string, object>> values) {
26 EntityType = entityType;
27 this.values =
new Dictionary<string, object>();
29 foreach (var pair
in values) {
30 this.values[pair.Key] = pair.Value;
35 public Type EntityType {
get;
private set; }
38 get {
return values.Count; }
42 if (String.IsNullOrEmpty(key))
43 throw new ArgumentNullException(
"key");
45 return values.ContainsKey(key);
49 if (String.IsNullOrEmpty(key))
50 throw new ArgumentNullException(
"key");
53 if (!values.TryGetValue(key, out value))
59 public T GetValue<T>(
string key) {
60 var value = GetValue(key);
67 if (!(value is IConvertible))
68 throw new InvalidCastException();
70 return (T) Convert.ChangeType(value, typeof (T), CultureInfo.InvariantCulture);
74 return GetValue<bool>(key);
78 return GetValue<byte>(key);
82 return GetValue<short>(key);
86 return GetValue<int>(key);
90 return GetValue<long>(key);
94 return GetValue<float>(key);
98 return GetValue<double>(key);
102 return GetValue<string>(key);
readonly Dictionary< string, object > values
long GetInt64(string key)
short GetInt16(string key)
ObjectData(Type entityType, IEnumerable< KeyValuePair< string, object >> values)
bool GetBoolean(string key)
double GetDouble(string key)
object GetValue(string key)
float GetSingle(string key)
bool HasValue(string key)
string GetString(string key)