C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
ResourcePathBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Globalization;
4using System.Linq;
5
6namespace AnalyzeRe.APITypes
7{
11 internal abstract class ResourcePathBuilder
12 {
13 protected abstract string base_path { get; }
14 private readonly string _primaryKey;
15
17 public string SubResource => $"{base_path}{_primaryKey}";
18
20 protected ResourcePathBuilder() { _primaryKey = ""; }
21
25 protected ResourcePathBuilder(string primaryKey) => _primaryKey = $"/{primaryKey}";
26
27 protected ResourcePathBuilder(double primaryKey) : this(FormatDouble(primaryKey)) { }
28
29 protected ResourcePathBuilder(ProbabilityWindow primaryKey)
30 : this($"{FormatDouble(primaryKey.min_probability)}_{FormatDouble(primaryKey.max_probability)}") { }
31
32 protected ResourcePathBuilder(long primaryKey)
33 : this(primaryKey.ToString("0", CultureInfo.InvariantCulture)) { }
34
35 protected ResourcePathBuilder(IEnumerable<double> primaryKey)
36 : this(String.Join(",", primaryKey.Select(FormatDouble))) { }
37
38 protected ResourcePathBuilder(IEnumerable<ProbabilityWindow> primaryKey)
39 : this(String.Join(",", primaryKey.Select(
40 k => $"{FormatDouble(k.min_probability)}_{FormatDouble(k.max_probability)}"))) { }
41
42 public override string ToString() => SubResource;
43
44 public static implicit operator string(ResourcePathBuilder x) => x.ToString();
45
46 private static string FormatDouble(double d) => d.ToString("G17", CultureInfo.InvariantCulture);
47 }
48}