public static IEnumerable <PropertyInfo> GetPropertiesWithAttr(this object obj, Type[] attributeTypes, Type[] excludedAttributeTypes = null) { if (obj == null) { return(Arr.Empty <PropertyInfo>()); } var props = obj.GetType() .GetProperties() .Where(p => p.GetCustomAttributes(true).Any(t => attributeTypes.Any(at => at == t.GetType()))); if (excludedAttributeTypes != null) { return(props.Where(p => excludedAttributeTypes.All(e => p.GetCustomAttribute(e) == null) )); } return(props); }
private static IHtmlContent CreateAutocomplete <T>(this IHtmlHelper <T> helper, string name, string url, int resultsPerPage, object htmlAttributes, SelectListItem[] defaultItems = null) { var values = htmlAttributes.ToDictionary(); foreach (var valuesKey in values.Keys.ToArray()) { if (valuesKey.StartsWith("data_")) { var value = values[valuesKey]; values.Remove(valuesKey); var newKey = valuesKey.Replace("_", "-"); values.Add(newKey, value); } } values.Add("data-select2-autocomplete", true); values.Add("data-url", url); values.Add("data-select2-resultsPerPage", resultsPerPage); return(helper.DropDownList(name, defaultItems ?? Arr.Empty <SelectListItem>(), htmlAttributes: values)); }
public UserMessage() { MessageTitle = "Вы уверены?"; MessageIdentifier = DateTime.Now.Ticks.ToString(); Buttons = Arr.Empty <IHtmlContent>(); }