/// <summary> /// Builds the options entries from the type. /// </summary> /// <param name="forType">The type of the options class.</param> /// <returns>A list of all public properties annotated for options dialogs.</returns> internal static IDictionary <string, OptionsList> BuildOptions(Type forType) { var entries = new SortedList <string, OptionsList>(8); OptionAttribute oa; DynamicOptionAttribute doa; foreach (var prop in forType.GetProperties()) { // Must have the annotation foreach (var attr in prop.GetCustomAttributes(false)) { if ((oa = OptionAttribute.CreateFrom(attr)) != null) { // Attempt to find a class that will represent it var entry = CreateOptions(prop, oa); if (entry != null) { AddToCategory(entries, entry); } break; } else if ((doa = DynamicOptionAttribute.CreateFrom(attr)) != null) { AddToCategory(entries, DynamicOptionsEntry.Create(prop.Name, doa)); break; } } } return(entries); }
internal static IDictionary <string, OptionsList> AddCustomOptions(object options, IDictionary <string, OptionsList> existing) { System.Collections.IEnumerable customOptions = null; // Call the user handler var createOptions = PPatchTools.GetMethodSafe(options.GetType(), nameof(IOptions. CreateOptions), false); var entries = existing; if (createOptions != null) { try { customOptions = createOptions.Invoke(options, null) as System. Collections.IEnumerable; } catch (TargetInvocationException e) { PUtil.LogException(e.GetBaseException()); } } if (customOptions != null) { // Middle-depth copy of the existing categories as it can change on each dialog entries = new SortedList <string, OptionsList>(entries.Count); foreach (var pair in existing) { entries.Add(pair.Key, new List <OptionsEntry>(pair.Value)); } foreach (var value in customOptions) { if (value != null) { AddToCategory(entries, DynamicOptionsEntry.Create(value)); } } } return(entries); }