Skip to content

Commit

Permalink
fix enum desrialization in GetProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Sep 17, 2021
1 parent d9cad04 commit 079b4b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

<h3 align="center">

![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=hotfix/1.1.2-1)
![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=hotfix/1.1.3)
[![NuGet](https://img.shields.io/nuget/vpre/DotNetStac)](https://www.nuget.org/packages/DotNetStac/)
[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/hotfix/1.1.2-1/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac)
[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/hotfix/1.1.3/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac)
[![Gitter](https://img.shields.io/gitter/room/SpatioTemporal-Asset-Catalog/Lobby?color=yellow)](https://gitter.im/SpatioTemporal-Asset-Catalog/Lobby)
[![License](https://img.shields.io/badge/license-AGPL3-blue.svg)](LICENSE)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Terradue/DotNetStac/master?filepath=example.ipynb)
Expand Down
20 changes: 20 additions & 0 deletions src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using GeoJSON.Net.Geometry;
using Stac.Collection;
using Stac.Common;
using Xunit;

Expand Down Expand Up @@ -48,6 +49,25 @@ public void GetPropertyTest()

Assert.Equal(dataType, item.GetProperty<DataType?>("test"));


SummaryItemType summaryItemType = default(SummaryItemType);

item.SetProperty("summary", summaryItemType);

Assert.NotNull(item.GetProperty<SummaryItemType>("summary"));

summaryItemType = SummaryItemType.RangeObject;

item.SetProperty("summary", summaryItemType);

Assert.Equal(summaryItemType, item.GetProperty<SummaryItemType>("summary"));

itemJson = StacConvert.Serialize(item);

item = StacConvert.Deserialize<StacItem>(itemJson);

Assert.Equal(summaryItemType, item.GetProperty<SummaryItemType>("summary"));

}
}
}
4 changes: 2 additions & 2 deletions src/DotNetStac/StacAccessorsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static T GetProperty<T>(this IDictionary<string, object> properties, stri
if (t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
t = Nullable.GetUnderlyingType(t);
if (t.GetTypeInfo().IsEnum)
return (T)Enum.Parse(t, @object.ToString());
}
if (t.GetTypeInfo().IsEnum)
return (T)Enum.Parse(t, @object.ToString());
return ChangeType<T>(@object);
}

Expand Down

0 comments on commit 079b4b7

Please sign in to comment.