Skip to content

Commit cb85602

Browse files
authored
Update libs (#5)
* updated to use Azure.Data.Tables SDK * fix package version * fix package again * oops * update readme and version
1 parent 1dce7c7 commit cb85602

File tree

5 files changed

+89
-79
lines changed

5 files changed

+89
-79
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ This simple library seeks to take care of the mapping for us, so that you can co
1515

1616
The library will convert simple properties to fields in Azure Table Storage. Complex types will serialize as json.
1717

18+
## :bangbang: Important Note About Versioning
19+
`TableStorage.Abstractions.TableEntityConverters` uses semantic versioning. Anything changes to a major release should not be breaking, e.g. upgrading to 1.5 from 1.4 should not require a code change.
20+
21+
The upgrade from 1.5 to 2.0 does not introduce changes needed in your use of `TableStorage.Abstractions.TableEntityConverters`, however the underlying table storage SDK is now using the newer [Azure.Data.Tables](https://www.nuget.org/packages/Azure.Data.Tables/) instead of the older [Microsoft.Azure.Cosmos.Table](https://www.nuget.org/packages/Microsoft.Azure.Cosmos.Table/) SDK.
22+
23+
If you directly use Microsoft's Table Storage SDK, you will need to use `Azure.Data.Tables`. It should not require much change, but nevertheless it is a change. If you do not want to upgrade at this time, stick with `TableStorage.Abstractions.TableEntityConverters` 1.5.
24+
25+
1826
Examples
1927
========
2028
We'll use the following two classes for our examples
@@ -144,8 +152,8 @@ property name and the value is a `PropertyConverter`, which specifies how to con
144152
var propertyConverters = new PropertyConverters<Car> {
145153
[nameof(Car.ReleaseDate)] =
146154
new PropertyConverter<Car>(x =>
147-
new EntityProperty(car.ReleaseDate.ToString("yyyy-M-d")),
148-
(c,p) =>c.ReleaseDate = DateTime.Parse(p.StringValue)
155+
car.ReleaseDate.ToString("yyyy-M-d"),
156+
(c,p) => c.ReleaseDate = p.ToString())
149157
)
150158
};
151159
```

src/TableStorage.Abstractions.TableEntityConverters/EntityConvert.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Linq;
55
using System.Linq.Expressions;
66
using System.Reflection;
7-
using Microsoft.Azure.Cosmos.Table;
7+
using Azure.Data.Tables;
88

99
namespace TableStorage.Abstractions.TableEntityConverters
1010
{
@@ -22,12 +22,12 @@ public static void SetDefaultJsonSerializerSettings (JsonSerializerSettings json
2222
_defaultJsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings();
2323
}
2424

25-
public static DynamicTableEntity ToTableEntity<T>(this T o, string partitionKey, string rowKey,
25+
public static TableEntity ToTableEntity<T>(this T o, string partitionKey, string rowKey,
2626
params Expression<Func<T, object>>[] ignoredProperties)
2727
{
2828
return ToTableEntity(o, partitionKey, rowKey, _defaultJsonSerializerSettings, default, ignoredProperties);
2929
}
30-
public static DynamicTableEntity ToTableEntity<T>(this T o, string partitionKey, string rowKey,
30+
public static TableEntity ToTableEntity<T>(this T o, string partitionKey, string rowKey,
3131
JsonSerializerSettings jsonSerializerSettings,
3232
PropertyConverters<T> propertyConverters = default,
3333
params Expression<Func<T, object>>[] ignoredProperties)
@@ -39,14 +39,14 @@ public static DynamicTableEntity ToTableEntity<T>(this T o, string partitionKey,
3939
return CreateTableEntity(o, properties, partitionKey, rowKey, jsonSerializerSettings, propertyConverters);
4040
}
4141

42-
public static DynamicTableEntity ToTableEntity<T>(this T o, Expression<Func<T, object>> partitionProperty,
42+
public static TableEntity ToTableEntity<T>(this T o, Expression<Func<T, object>> partitionProperty,
4343
Expression<Func<T, object>> rowProperty,
4444
params Expression<Func<T, object>>[] ignoredProperties)
4545
{
4646
return ToTableEntity(o, partitionProperty, rowProperty, _defaultJsonSerializerSettings, null, ignoredProperties);
4747
}
4848

49-
public static DynamicTableEntity ToTableEntity<T>(this T o, Expression<Func<T, object>> partitionProperty,
49+
public static TableEntity ToTableEntity<T>(this T o, Expression<Func<T, object>> partitionProperty,
5050
Expression<Func<T, object>> rowProperty, JsonSerializerSettings jsonSerializerSettings,
5151
PropertyConverters<T> propertyConverters = default,
5252
params Expression<Func<T, object>>[] ignoredProperties)
@@ -76,14 +76,14 @@ public static DynamicTableEntity ToTableEntity<T>(this T o, Expression<Func<T, o
7676
return CreateTableEntity(o, properties, partitionKey, rowKey, jsonSerializerSettings, propertyConverters);
7777
}
7878

79-
public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
79+
public static T FromTableEntity<T, TP, TR>(this TableEntity entity,
8080
Expression<Func<T, object>> partitionProperty,
8181
Expression<Func<T, object>> rowProperty) where T : new()
8282
{
8383
return FromTableEntity<T, TP, TR>(entity, partitionProperty, rowProperty, _defaultJsonSerializerSettings);
8484
}
8585

86-
public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
86+
public static T FromTableEntity<T, TP, TR>(this TableEntity entity,
8787
Expression<Func<T, object>> partitionProperty,
8888
Expression<Func<T, object>> rowProperty,
8989
JsonSerializerSettings jsonSerializerSettings,
@@ -106,7 +106,7 @@ public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
106106
rowProperty, convertRow, jsonSerializerSettings, propertyConverters);
107107
}
108108

109-
public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
109+
public static T FromTableEntity<T, TP, TR>(this TableEntity entity,
110110
Expression<Func<T, object>> partitionProperty,
111111
Func<string, TP> convertPartitionKey, Expression<Func<T, object>> rowProperty,
112112
Func<string, TR> convertRowKey) where T : new()
@@ -115,7 +115,7 @@ public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
115115
convertRowKey, _defaultJsonSerializerSettings);
116116
}
117117

118-
public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
118+
public static T FromTableEntity<T, TP, TR>(this TableEntity entity,
119119
Expression<Func<T, object>> partitionProperty,
120120
Func<string, TP> convertPartitionKey, Expression<Func<T, object>> rowProperty,
121121
Func<string, TR> convertRowKey, JsonSerializerSettings jsonSerializerSettings,
@@ -156,12 +156,12 @@ public static T FromTableEntity<T, TP, TR>(this DynamicTableEntity entity,
156156
return o;
157157
}
158158

159-
public static T FromTableEntity<T>(this DynamicTableEntity entity) where T : new()
159+
public static T FromTableEntity<T>(this TableEntity entity) where T : new()
160160
{
161161
return FromTableEntity<T>(entity, _defaultJsonSerializerSettings);
162162
}
163163

164-
public static T FromTableEntity<T>(this DynamicTableEntity entity,
164+
public static T FromTableEntity<T>(this TableEntity entity,
165165
JsonSerializerSettings jsonSerializerSettings, PropertyConverters<T> propertyConverters = default) where T : new()
166166
{
167167
_ = jsonSerializerSettings ?? throw new ArgumentNullException(nameof(jsonSerializerSettings));
@@ -188,10 +188,10 @@ internal static string GetPropertyNameFromExpression<T>(Expression<Func<T, objec
188188
return name;
189189
}
190190

191-
private static void SetTimestamp<T>(DynamicTableEntity entity, T o, List<PropertyInfo> properties) where T : new()
191+
private static void SetTimestamp<T>(TableEntity entity, T o, List<PropertyInfo> properties) where T : new()
192192
{
193193
var timestampProperty = properties
194-
.FirstOrDefault(p => p.Name == nameof(DynamicTableEntity.Timestamp));
194+
.FirstOrDefault(p => p.Name == nameof(TableEntity.Timestamp));
195195

196196
if (timestampProperty != null)
197197
{
@@ -202,7 +202,7 @@ internal static string GetPropertyNameFromExpression<T>(Expression<Func<T, objec
202202

203203
if (timestampProperty.PropertyType == typeof(DateTime))
204204
{
205-
timestampProperty.SetValue(o, entity.Timestamp.UtcDateTime);
205+
timestampProperty.SetValue(o, entity.Timestamp?.UtcDateTime);
206206
}
207207

208208
if (timestampProperty.PropertyType == typeof(string))
@@ -212,48 +212,48 @@ internal static string GetPropertyNameFromExpression<T>(Expression<Func<T, objec
212212
}
213213
}
214214

215-
private static void FillProperties<T>(DynamicTableEntity entity, T o, List<PropertyInfo> properties, JsonSerializerSettings jsonSerializerSettings, PropertyConverters<T> propertyConverters) where T : new()
215+
private static void FillProperties<T>(TableEntity entity, T o, List<PropertyInfo> properties, JsonSerializerSettings jsonSerializerSettings, PropertyConverters<T> propertyConverters) where T : new()
216216
{
217217
foreach (var propertyInfo in properties)
218218
{
219-
if (propertyConverters != null && entity.Properties.ContainsKey(propertyInfo.Name) && propertyConverters.ContainsKey(propertyInfo.Name))
219+
if (propertyConverters != null && entity.Keys.Contains(propertyInfo.Name) && propertyConverters.ContainsKey(propertyInfo.Name))
220220
{
221-
propertyConverters[propertyInfo.Name].SetObjectProperty(o, entity.Properties[propertyInfo.Name]);
221+
propertyConverters[propertyInfo.Name].SetObjectProperty(o, entity[propertyInfo.Name]);
222222
}
223-
else if (entity.Properties.ContainsKey(propertyInfo.Name) && propertyInfo.Name != nameof(DynamicTableEntity.Timestamp))
223+
else if (entity.Keys.Contains(propertyInfo.Name) && propertyInfo.Name != nameof(TableEntity.Timestamp))
224224
{
225-
var val = entity.Properties[propertyInfo.Name].PropertyAsObject;
225+
var val = entity[propertyInfo.Name];
226226

227227
if (val != null && (propertyInfo.PropertyType == typeof(DateTimeOffset) || propertyInfo.PropertyType == typeof(DateTimeOffset?)))
228228
{
229-
val = entity.Properties[propertyInfo.Name].DateTimeOffsetValue;
229+
val = entity.GetDateTimeOffset(propertyInfo.Name);
230230
}
231231

232232
if (val != null && propertyInfo.PropertyType == typeof(double))
233233
{
234-
val = entity.Properties[propertyInfo.Name].DoubleValue;
234+
val = entity.GetDouble(propertyInfo.Name);
235235
}
236236

237237
if (val != null && propertyInfo.PropertyType == typeof(int))
238238
{
239-
val = entity.Properties[propertyInfo.Name].Int32Value;
239+
val = entity.GetInt32(propertyInfo.Name);
240240
}
241241

242242
if (val != null && propertyInfo.PropertyType == typeof(long))
243243
{
244-
val = entity.Properties[propertyInfo.Name].Int64Value;
244+
val = entity.GetInt64(propertyInfo.Name);
245245
}
246246

247247
if (val != null && propertyInfo.PropertyType == typeof(Guid))
248248
{
249-
val = entity.Properties[propertyInfo.Name].GuidValue;
249+
val = entity.GetGuid(propertyInfo.Name);
250250
}
251251

252252
propertyInfo.SetValue(o, val);
253253
}
254-
else if (entity.Properties.ContainsKey($"{propertyInfo.Name}Json"))
254+
else if (entity.Keys.Contains($"{propertyInfo.Name}Json"))
255255
{
256-
var val = entity.Properties[$"{propertyInfo.Name}Json"].StringValue;
256+
var val = entity.GetString($"{propertyInfo.Name}Json");
257257
if (val != null)
258258
{
259259
var propVal = JsonConvert.DeserializeObject(val, propertyInfo.PropertyType, jsonSerializerSettings ?? _defaultJsonSerializerSettings);
@@ -263,15 +263,15 @@ internal static string GetPropertyNameFromExpression<T>(Expression<Func<T, objec
263263
}
264264
}
265265

266-
private static DynamicTableEntity CreateTableEntity<T>(object o, List<PropertyInfo> properties,
266+
private static TableEntity CreateTableEntity<T>(object o, List<PropertyInfo> properties,
267267
string partitionKey, string rowKey, JsonSerializerSettings jsonSerializerSettings, PropertyConverters<T> propertyConverters)
268268
{
269-
var entity = new DynamicTableEntity(partitionKey, rowKey);
269+
var entity = new TableEntity(partitionKey, rowKey);
270270
foreach (var propertyInfo in properties)
271271
{
272272
var name = propertyInfo.Name;
273273
var val = propertyInfo.GetValue(o);
274-
EntityProperty entityProperty;
274+
object entityProperty;
275275
if (propertyConverters != null && propertyConverters.ContainsKey(name))
276276
{
277277
entityProperty = propertyConverters[name].ToTableEntityProperty((T)o);
@@ -281,50 +281,50 @@ private static DynamicTableEntity CreateTableEntity<T>(object o, List<PropertyIn
281281
switch (val)
282282
{
283283
case int x:
284-
entityProperty = new EntityProperty(x);
284+
entityProperty = x;
285285
break;
286286
case short x:
287-
entityProperty = new EntityProperty(x);
287+
entityProperty = x;
288288
break;
289289
case byte x:
290-
entityProperty = new EntityProperty(x);
290+
entityProperty = x;
291291
break;
292292
case string x:
293-
entityProperty = new EntityProperty(x);
293+
entityProperty = x;
294294
break;
295295
case double x:
296-
entityProperty = new EntityProperty(x);
296+
entityProperty = x;
297297
break;
298298
case DateTime x:
299-
entityProperty = new EntityProperty(x);
299+
entityProperty = x;
300300
break;
301301
case DateTimeOffset x:
302-
entityProperty = new EntityProperty(x);
302+
entityProperty = x;
303303
break;
304304
case bool x:
305-
entityProperty = new EntityProperty(x);
305+
entityProperty = x;
306306
break;
307307
case byte[] x:
308-
entityProperty = new EntityProperty(x);
308+
entityProperty = x;
309309
break;
310310
case long x:
311-
entityProperty = new EntityProperty(x);
311+
entityProperty = x;
312312
break;
313313
case Guid x:
314-
entityProperty = new EntityProperty(x);
314+
entityProperty = x;
315315
break;
316316
case null:
317-
entityProperty = new EntityProperty((int?)null);
317+
entityProperty = null;
318318
break;
319319
default:
320320
name += "Json";
321-
entityProperty = new EntityProperty(JsonConvert.SerializeObject(val,
322-
jsonSerializerSettings ?? _defaultJsonSerializerSettings));
321+
entityProperty = JsonConvert.SerializeObject(val,
322+
jsonSerializerSettings ?? _defaultJsonSerializerSettings);
323323
break;
324324
}
325325
}
326326

327-
entity.Properties[name] = entityProperty;
327+
entity[name] = entityProperty;
328328
}
329329
return entity;
330330
}

src/TableStorage.Abstractions.TableEntityConverters/PropertyConverters.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3-
using Microsoft.Azure.Cosmos.Table;
43

54
namespace TableStorage.Abstractions.TableEntityConverters
65
{
76
public class PropertyConverter<T>
87
{
9-
public Func<T, EntityProperty> ToTableEntityProperty { get; }
10-
public Action<T,EntityProperty> SetObjectProperty { get; }
8+
public Func<T, object> ToTableEntityProperty { get; }
9+
public Action<T, object> SetObjectProperty { get; }
1110

12-
public PropertyConverter(Func<T, EntityProperty> toTableEntityProperty, Action<T, EntityProperty> setObjectProperty)
11+
public PropertyConverter(Func<T, object> toTableEntityProperty, Action<T, object> setObjectProperty)
1312
{
1413
ToTableEntityProperty = toTableEntityProperty;
1514
SetObjectProperty = setObjectProperty;

src/TableStorage.Abstractions.TableEntityConverters/TableStorage.Abstractions.TableEntityConverters.csproj

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5-
<Version>1.3.2.0</Version>
5+
<Version>2.0.0.0</Version>
66
<Authors>Giovanni Galbo</Authors>
77
<Company>Giovanni Galbo</Company>
88
<Description>Easily convert POCOs (Plain Old CLR Objects) to Azure Table Storage TableEntities and vice versa.</Description>
9-
<Copyright>Giovanni Galbo © 2021</Copyright>
9+
<Copyright>Giovanni Galbo © 2022</Copyright>
1010
<PackageLicenseUrl></PackageLicenseUrl>
1111
<PackageProjectUrl>https://github.com/giometrix/TableStorage.Abstractions.TableEntityConverters</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/giometrix/TableStorage.Abstractions.TableEntityConverters</RepositoryUrl>
1313
<PackageTags>table-storage azure-table-storage poco table-entities</PackageTags>
14-
<PackageReleaseNotes>Allows for custom serialization of properties</PackageReleaseNotes>
14+
<PackageReleaseNotes>Updated to use newer Azure.Data.Tables SDK</PackageReleaseNotes>
1515
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1616
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1717
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -20,13 +20,17 @@
2020
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2121
<IncludeSymbols>true</IncludeSymbols>
2222
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
23-
<AssemblyVersion>1.3.2.0</AssemblyVersion>
23+
<AssemblyVersion>2.0.0.0</AssemblyVersion>
2424
<Nullable>disable</Nullable>
25-
<PackageVersion>1.5.0.0</PackageVersion>
25+
<PackageVersion>2.0.0.0</PackageVersion>
26+
<SignAssembly>False</SignAssembly>
27+
<PackageReadmeFile>README.md</PackageReadmeFile>
2628
</PropertyGroup>
2729

2830
<ItemGroup>
29-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
31+
<PackageReference Include="Azure.Data.Tables" Version="12.4.0" />
32+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
33+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
3034
</ItemGroup>
3135

3236

@@ -35,10 +39,10 @@
3539
</PropertyGroup>
3640

3741
<ItemGroup>
38-
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.8" />
39-
</ItemGroup>
40-
41-
<ItemGroup>
42+
<None Include="..\..\README.md">
43+
<Pack>True</Pack>
44+
<PackagePath>\</PackagePath>
45+
</None>
4246
<None Include="..\..\xtensible-x.png">
4347
<Pack>True</Pack>
4448
<PackagePath></PackagePath>

0 commit comments

Comments
 (0)