// returns value / display name public KeyValuePair <string, string> GetValue(object settings, CodeFormatOption option) { PropertyInfo info = settings.GetType().GetProperty(option.Name); string value = info.GetValue(settings, null).ToString(); CodeFormatType type = GetCodeFormatType(settings, option); return(new KeyValuePair <string, string> (value, type.GetValue(value).Value)); }
public CodeFormatType GetCodeFormatType(object settings, CodeFormatOption option) { PropertyInfo info = settings.GetType().GetProperty(option.Name); if (info == null) { throw new System.InvalidOperationException(option.Name + " not found in " + settings); } if (info.PropertyType == typeof(bool)) { return(codeFormatTypeBool); } return(types.FirstOrDefault(t => t.Name == info.PropertyType.Name)); }
public void SetValue(object settings, CodeFormatOption option, string value) { PropertyInfo info = settings.GetType().GetProperty(option.Name); object val; if (typeof(System.Enum).IsAssignableFrom(info.PropertyType)) { val = Enum.Parse(info.PropertyType, value); } else { val = Convert.ChangeType(value, info.PropertyType); } info.SetValue(settings, val, null); }
public static CodeFormatOption Read(CodeFormatDescription descr, XmlReader reader) { CodeFormatOption result = new CodeFormatOption(); result.Name = reader.GetAttribute("name"); result.DisplayName = reader.GetAttribute("_displayName"); string example = reader.GetAttribute("example"); if (!string.IsNullOrEmpty(example)) { result.Example = descr.GetExample(example); } if (!reader.IsEmptyElement) { reader.Read(); result.Example = reader.ReadElementString(); reader.Read(); } return(result); }
public static CodeFormatCategory Read(CodeFormatDescription descr, XmlReader reader) { CodeFormatCategory result = new CodeFormatCategory(); result.IsOptionCategory = reader.LocalName == OptionCategoryNode; result.DisplayName = reader.GetAttribute("_displayName"); XmlReadHelper.ReadList(reader, result.IsOptionCategory ? OptionCategoryNode : Node, delegate() { switch (reader.LocalName) { case "Option": result.options.Add(CodeFormatOption.Read(descr, reader)); return(true); case CodeFormatCategory.OptionCategoryNode: case CodeFormatCategory.Node: result.subCategories.Add(CodeFormatCategory.Read(descr, reader)); return(true); } return(false); }); return(result); }
public void SetValue (object settings, CodeFormatOption option, string value) { PropertyInfo info = settings.GetType ().GetProperty (option.Name); object val; if (typeof (System.Enum).IsAssignableFrom (info.PropertyType)) { val = Enum.Parse (info.PropertyType, value); } else { val = Convert.ChangeType (value, info.PropertyType); } info.SetValue (settings, val, null); }
// returns value / display name public KeyValuePair<string, string> GetValue (object settings, CodeFormatOption option) { PropertyInfo info = settings.GetType ().GetProperty (option.Name); string value = info.GetValue (settings, null).ToString (); CodeFormatType type = GetCodeFormatType (settings, option); return new KeyValuePair<string, string> (value, type.GetValue (value).Value); }
public CodeFormatType GetCodeFormatType (object settings, CodeFormatOption option) { PropertyInfo info = settings.GetType ().GetProperty (option.Name); if (info == null) throw new System.InvalidOperationException (option.Name + " not found in " + settings); if (info.PropertyType == typeof (bool)) return codeFormatTypeBool; return types.FirstOrDefault (t => t.Name == info.PropertyType.Name); }
public static CodeFormatOption Read (CodeFormatDescription descr, XmlReader reader) { CodeFormatOption result = new CodeFormatOption (); result.Name = reader.GetAttribute ("name"); result.DisplayName = reader.GetAttribute ("_displayName"); string example = reader.GetAttribute ("example"); if (!string.IsNullOrEmpty (example)) result.Example = descr.GetExample (example); if (!reader.IsEmptyElement) { reader.Read (); result.Example = reader.ReadElementString (); reader.Read (); } return result; }