public static OptionInfo[] GetOptions(CodeFormattingCategory category) { List <OptionInfo> res; if (!_cachedOptions.TryGetValue(category, out res)) { res = new List <OptionInfo>(); foreach (var prop in typeof(CodeFormattingOptions).GetProperties()) { var attrs = prop.GetCustomAttributes(typeof(CodeFormattingCategoryAttribute), false); if (attrs.Length > 0) { if (((CodeFormattingCategoryAttribute)attrs[0]).Category == category) { var desc = prop.GetCustomAttributes(typeof(CodeFormattingDescriptionAttribute), false); string descStr = prop.Name, toolTip = ""; if (desc.Length > 0) { descStr = ((CodeFormattingDescriptionAttribute)desc[0]).ShortDescription; toolTip = ((CodeFormattingDescriptionAttribute)desc[0]).LongDescription; } string previewOn = "", previewOff = ""; desc = prop.GetCustomAttributes(typeof(CodeFormattingExampleAttribute), false); if (desc.Length > 0) { previewOn = ((CodeFormattingExampleAttribute)desc[0]).On; previewOff = ((CodeFormattingExampleAttribute)desc[0]).Off; } ; object defaultValue = null; desc = prop.GetCustomAttributes(typeof(CodeFormattingDefaultValueAttribute), false); if (desc.Length > 0) { defaultValue = ((CodeFormattingDefaultValueAttribute)desc[0]).DefaultValue; } if (prop.PropertyType == typeof(bool)) { res.Add(new BooleanOptionInfo(descStr, prop.Name, toolTip, previewOn, previewOff, (bool)defaultValue)); } else if (prop.PropertyType == typeof(bool?)) { res.Add(new TriStateOptionInfo(descStr, prop.Name, toolTip, previewOn, previewOff, (bool?)defaultValue)); } else if (prop.PropertyType == typeof(int)) { res.Add(new IntegerOptionInfo(descStr, prop.Name, toolTip, previewOn, (int)defaultValue)); } else { throw new InvalidOperationException(); } } } } } return(res.ToArray()); }
public static OptionInfo[] GetOptions(CodeFormattingCategory category) { List<OptionInfo> res; if (!_cachedOptions.TryGetValue(category, out res)) { res = new List<OptionInfo>(); foreach (var prop in typeof(CodeFormattingOptions).GetProperties()) { var attrs = prop.GetCustomAttributes(typeof(CodeFormattingCategoryAttribute), false); if (attrs.Length > 0) { if (((CodeFormattingCategoryAttribute)attrs[0]).Category == category) { var desc = prop.GetCustomAttributes(typeof(CodeFormattingDescriptionAttribute), false); string descStr = prop.Name, toolTip = ""; if (desc.Length > 0) { descStr = ((CodeFormattingDescriptionAttribute)desc[0]).ShortDescription; toolTip = ((CodeFormattingDescriptionAttribute)desc[0]).LongDescription; } string previewOn = "", previewOff = ""; desc = prop.GetCustomAttributes(typeof(CodeFormattingExampleAttribute), false); if (desc.Length > 0) { previewOn = ((CodeFormattingExampleAttribute)desc[0]).On; previewOff = ((CodeFormattingExampleAttribute)desc[0]).Off; }; object defaultValue = null; desc = prop.GetCustomAttributes(typeof(CodeFormattingDefaultValueAttribute), false); if (desc.Length > 0) { defaultValue = ((CodeFormattingDefaultValueAttribute)desc[0]).DefaultValue; } if (prop.PropertyType == typeof(bool)) { res.Add(new BooleanOptionInfo(descStr, prop.Name, toolTip, previewOn, previewOff, (bool)defaultValue)); } else if (prop.PropertyType == typeof(bool?)) { res.Add(new TriStateOptionInfo(descStr, prop.Name, toolTip, previewOn, previewOff, (bool?)defaultValue)); }else if(prop.PropertyType == typeof(int)) { res.Add(new IntegerOptionInfo(descStr, prop.Name, toolTip, previewOn, (int)defaultValue)); } else { throw new InvalidOperationException(); } } } } } return res.ToArray(); }
internal CodeFormattingCategoryAttribute(CodeFormattingCategory category) { _category = category; }
public static OptionInfo[] GetOptions(CodeFormattingCategory category) => _cachedOptions.TryGetValue(category, out var options) ? options.ToArray() : new OptionInfo[0];