2 using System.Collections.Generic;
5 using System.Web.DynamicData;
7 namespace MonoTests.Common
9 class FieldFormattingOptions : IFieldFormattingOptions
11 Dictionary<string, object> propertyValues = new Dictionary<string, object> ();
13 public bool ApplyFormatInEditMode
15 get { return GetProperty <bool> ("ApplyFormatInEditMode"); }
18 public bool ConvertEmptyStringToNull
20 get { return GetProperty <bool> ("ConvertEmptyStringToNull"); }
23 public string DataFormatString
25 get { return GetProperty <string> ("DataFormatString"); }
28 public bool HtmlEncode
30 get { return GetProperty <bool> ("HtmlEncode"); }
33 public string NullDisplayText
35 get { return GetProperty <string> ("NullDisplayText"); }
38 T GetProperty<T> (string name)
40 if (String.IsNullOrEmpty (name))
41 throw new ArgumentNullException ("name");
44 if (propertyValues.TryGetValue (name, out v)) {
47 if (typeof (T).IsAssignableFrom (v.GetType ())) {
51 throw new InvalidOperationException ("Invalid value type. Expected '" + typeof (T) + "' and got '" + v.GetType () + "'");
57 public void SetProperty (string name, object value)
59 if (String.IsNullOrEmpty (name))
62 if (propertyValues.ContainsKey (name))
63 propertyValues[name] = value;
65 propertyValues.Add (name, value);