-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPropertyValue.cs
39 lines (29 loc) · 958 Bytes
/
PropertyValue.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
using MapboxMaui.Expressions;
namespace MapboxMaui;
public interface IPropertyValue
{
public object Value { get; }
}
public record class PropertyValue<T> : IPropertyValue
{
public T Constant { get; }
public DslExpression Expression { get; }
public object Value => Expression ?? (object)Constant;
public PropertyValue(T value)
{
if (value is DslExpression)
{
throw new ArgumentException("Argument must not be a DslExpression", nameof(value));
}
Constant = value;
Expression = null;
}
public PropertyValue(DslExpression expression)
{
Expression = expression;
Constant = default;
}
public T GetConstant(T defaultValue) => Expression == null ? Constant : defaultValue;
public static implicit operator PropertyValue<T>(T value) => new(value);
public static explicit operator PropertyValue<T>(DslExpression value) => new(value);
}