-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
DocumentFilterOrder.cs
53 lines (49 loc) · 1.72 KB
/
DocumentFilterOrder.cs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Azure.AI.Translation.Document
{
/// <summary>
/// A class which defines sorting options
/// used in listing all document statuses for a certain translation operation.
/// </summary>
public class DocumentFilterOrder
{
/// <summary>
/// Initializes an instance of <see cref="DocumentFilterOrder"/>.
/// </summary>
public DocumentFilterOrder(DocumentFilterProperty property, bool ascending = true)
{
Property = property;
Ascending = ascending;
}
/// <summary>
/// Sort results ascendingly if true, or descendingly if false.
/// Default value is true.
/// </summary>
public bool Ascending { get; set; } = true;
/// <summary>
/// See <see cref="DocumentFilterProperty"/> for list of properties supported.
/// </summary>
public DocumentFilterProperty Property { get; set; }
/// <summary>
/// Convert the order filter to string.
/// </summary>
/// <returns></returns>
internal string ToGenerated()
{
// convert enum property to corresponding <see cref="DocumentStatus"/> model attribute
var property = string.Empty;
switch (Property)
{
case DocumentFilterProperty.CreatedOn:
property = "createdDateTimeUtc";
break;
default:
break;
}
// sorting direction
var direction = Ascending ? "Asc" : "Desc";
return $"{property} {direction}";
}
}
}