Skip to content

Commit

Permalink
Refactored querydecoder because you cannot simply remove the dot for …
Browse files Browse the repository at this point in the history
…dictionaries, as they are used by multiple query classes
  • Loading branch information
quirijnslings committed Sep 19, 2024
1 parent 113ed53 commit db108a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Bynder/Sample/UploadSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ private async Task RunUploadSampleAsync()
query.Description = description;
}


query.MetapropertyOptions = new Dictionary<string,IList<string>>()
{
{ "a", [ "b" ]}
};

FileStream fileStream = null;
if (passAsStream)
{
Expand Down
2 changes: 1 addition & 1 deletion Bynder/Sdk/Query/Asset/MediaQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class MediaQuery
/// - If the metaproperty is of type text, the values refer to the text itself
/// </remarks>
///
[ApiField("property_", Converter = typeof(MetapropertyOptionsConverter))]
[ApiField("property_", Converter = typeof(MetapropertyOptionsConverter), OmitSeparator = true)]
public IDictionary<string, IList<string>> MetaProperties { get; set; }

}
Expand Down
7 changes: 6 additions & 1 deletion Bynder/Sdk/Query/Decoder/ApiField.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Bynder. All rights reserved.
// Copyright (c) Bynder. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.

using System;
Expand Down Expand Up @@ -30,5 +30,10 @@ public ApiField(string name)
/// Name of the property in the API documentation.
/// </summary>
public string ApiName { get; private set; }

/// <summary>
/// Indicates whether or not the separator (usually a dot) must be omitted when converting
/// </summary>
public bool OmitSeparator { get; set; }
}
}
3 changes: 2 additions & 1 deletion Bynder/Sdk/Query/Decoder/QueryDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ private void ConvertProperty(PropertyInfo propertyInfo, object query, IDictionar
else if (Activator.CreateInstance(apiField.Converter) is ITypeToDictionaryConverter dictConverter
&& dictConverter.CanConvert(propertyInfo.PropertyType))
{
var separator = apiField.OmitSeparator ? string.Empty : ".";
foreach (var item in dictConverter.Convert(value))
{
AddParam(parameters, $"{apiField.ApiName}{item.Key}", item.Value);
AddParam(parameters, $"{apiField.ApiName}{separator}{item.Key}", item.Value);
}
}
}
Expand Down

0 comments on commit db108a5

Please sign in to comment.