-
Notifications
You must be signed in to change notification settings - Fork 5
/
FbUser.cs
61 lines (54 loc) · 1.87 KB
/
FbUser.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
54
55
56
57
58
59
60
61
using System.Collections.Generic;
namespace FeatBit.Sdk.Server.Model
{
public class FbUser
{
public readonly string Key;
public readonly string Name;
public readonly Dictionary<string, string> Custom;
internal FbUser(string key, string name, Dictionary<string, string> custom)
{
Key = key;
Name = name;
Custom = custom;
}
/// <summary>
/// Creates an <see cref="IFbUserBuilder"/> for constructing a user object using a fluent syntax.
/// </summary>
/// <remarks>
/// This is the only method for building a <see cref="FbUser"/>. The <see cref="IFbUserBuilder"/> has methods
/// for setting any number of properties, after which you call <see cref="IFbUserBuilder.Build"/> to get the
/// resulting <see cref="FbUser"/> instance.
/// </remarks>
/// <example>
/// <code>
/// var user = FbUser.Builder("a-unique-key-of-user")
/// .Name("user-name")
/// .Custom("email", "test@example.com")
/// .Build();
/// </code>
/// </example>
/// <param name="key">a <see langword="string"/> that uniquely identifies a user</param>
/// <returns>a builder object</returns>
public static IFbUserBuilder Builder(string key)
{
return new FbUserBuilder(key);
}
public string ValueOf(string property)
{
if (string.IsNullOrWhiteSpace(property))
{
return string.Empty;
}
if (property == "keyId")
{
return Key;
}
if (property == "name")
{
return Name;
}
return Custom.TryGetValue(property, out var value) ? value : string.Empty;
}
}
}