This repository was archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathDictionaryTableEntity.cs
More file actions
63 lines (47 loc) · 1.83 KB
/
DictionaryTableEntity.cs
File metadata and controls
63 lines (47 loc) · 1.83 KB
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
using Microsoft.Azure.Cosmos.Table;
using Azure.Storage;
using System;
using System.Collections.Generic;
namespace Microsoft.DataTransfer.AzureTable.FunctionalTests
{
sealed class DictionaryTableEntity : TableEntity
{
private readonly IReadOnlyDictionary<string, object> data;
public DictionaryTableEntity() { }
public DictionaryTableEntity(string key, IReadOnlyDictionary<string, object> data)
{
PartitionKey = String.Empty;
RowKey = key;
this.data = data;
}
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
var results = base.WriteEntity(operationContext);
foreach (var item in data)
results.Add(item.Key, AsEntityProperty(item.Value));
return results;
}
private static EntityProperty AsEntityProperty(object value)
{
if (value is bool)
return new EntityProperty((bool)value);
if (value is byte[])
return new EntityProperty((byte[])value);
if (value is DateTime)
return new EntityProperty((DateTime)value);
if (value is DateTimeOffset)
return new EntityProperty((DateTimeOffset)value);
if (value is double || value is float)
return new EntityProperty((double)value);
if (value is Guid)
return new EntityProperty((Guid)value);
if (value is int)
return new EntityProperty((int)value);
if (value is long)
return new EntityProperty((long)value);
if (value is string)
return new EntityProperty((string)value);
return new EntityProperty((string)null);
}
}
}