/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(object model) { bool showSelect = PropData.GetAdditionalAttributeValue("ShowSelect", false); List <SelectionItem <int> > list = GetEnumSelectionList(model.GetType(), showSelect: showSelect); return(await DropDownListIntComponent.RenderDropDownListAsync(this, (int)model, list, "yt_enum")); }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public async Task <string> RenderAsync(object model) { Type enumType = model.GetType(); // get all enum values in supported list List <int> supported = new List <int>(); object obj = GetSiblingProperty <object>($"{PropertyName}_Supported"); IEnumerable ienumerable = obj as IEnumerable; IEnumerator ienum = ienumerable.GetEnumerator(); while (ienum.MoveNext()) { supported.Add(Convert.ToInt32(ienum.Current)); } List <SelectionItem <int> > list = new List <SelectionItem <int> >(); EnumData enumData = ObjectSupport.GetEnumData(enumType); bool showValues = UserSettings.GetProperty <bool>("ShowEnumValue"); bool showSelect = PropData.GetAdditionalAttributeValue("ShowSelect", false); if (showSelect) { list.Add(new SelectionItem <int> { Text = __ResStr("enumSelect", "(select)"), Value = 0, Tooltip = __ResStr("enumPlsSelect", "Please select one of the available options"), }); } foreach (EnumDataEntry entry in enumData.Entries) { int enumVal = Convert.ToInt32(entry.Value); if (enumVal == 0 && showSelect) { continue; } if (supported.Contains(enumVal)) { string caption = entry.Caption; if (showValues) { caption = __ResStr("enumFmt", "{0} - {1}", enumVal, caption); } list.Add(new SelectionItem <int> { Text = caption, Value = enumVal, Tooltip = entry.Description, }); } } return(await DropDownListIntComponent.RenderDropDownListAsync(this, (int)model, list, "yt_enumsupported")); }