blob: 0929fc4a157ef1b3fb436381e6794d631fc8efe5 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Reflection;
using Xamarin.PropertyEditing.Resources;
namespace Xamarin.PropertyEditing.ViewModels
{
internal class EnumPropertyViewModel<TValue>
: PropertyViewModel<TValue>
where TValue : struct
{
public EnumPropertyViewModel (IPropertyInfo property, IEnumerable<IObjectEditor> editors)
: base (property, editors)
{
PossibleValues = Enum.GetNames (property.Type);
IsFlags = property.Type.GetCustomAttribute<FlagsAttribute> () != null;
}
public bool IsFlags
{
get;
}
public IReadOnlyList<string> PossibleValues
{
get;
}
public string ValueName
{
get { return Value.ToString (); }
set
{
TValue realValue;
if (!Enum.TryParse (value, out realValue)) {
SetError (string.Format (LocalizationResources.UnableToParseValue, value));
return;
}
Value = realValue;
}
}
protected override void OnValueChanged ()
{
base.OnValueChanged ();
OnPropertyChanged (nameof (ValueName));
}
}
}
|