public static IEnumerable <T> Skip <T>(this IReadOnlyList <T> collection, int count) { if (collection == null) { return(null); } return(ICollectionExtensions.YieldSkip(collection, count)); }
public string SaveExtendField_POST() { try { ExtendFieldDto extend = ICollectionExtensions.ConvertToEntity <ExtendFieldDto>(this.Request.Form); int result = ServiceCall.Instance.SiteService.SaveExtendField(this.SiteId, extend); return(base.ReturnSuccess()); } catch (Exception exc) { return(base.ReturnError(exc.Message)); } }
private static void OnInlinesChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { if (obj is TextBlock textBlock) { textBlock.Inlines.Clear(); if (e.NewValue is IEnumerable <InlineModel> inlines) { ICollectionExtensions.AddRange(textBlock.Inlines, inlines.Select(i => i.Create(textBlock))); } } else if (obj is Paragraph paragraph) { paragraph.Inlines.Clear(); if (e.NewValue is IEnumerable <InlineModel> inlines && RecursiveEnumerable.While(paragraph.Parent, obj => obj is FrameworkContentElement fce, obj => ((FrameworkContentElement)obj).Parent).LastOrDefault() is FrameworkElement fe) { ICollectionExtensions.AddRange(paragraph.Inlines, inlines.Select(i => i.Create(fe))); } } }
public static T GetEntity <T>() where T : new() { const bool allowError = false; global::System.Collections.Specialized.NameValueCollection form = global::System.Web.HttpContext.Current.Request.Form; Type type = typeof(T); object t = Activator.CreateInstance(type); PropertyInfo[] pros = type.GetProperties(); FormFieldAttribute[] fieldAttrs; FormFieldAttribute attr; string value; int tmpInt; Type strType = typeof(String); //字符串类型 Type bitType = typeof(Boolean); //布尔值类型 Type proType = null; //属性类型 foreach (PropertyInfo pro in pros) { if (!pro.CanWrite) { continue; } fieldAttrs = pro.GetCustomAttributes(typeof(FormFieldAttribute), false) as FormFieldAttribute[]; if (fieldAttrs.Length != 0) { attr = fieldAttrs[0]; value = form["field_" + pro.Name] ?? (form[pro.Name] ?? ""); proType = pro.PropertyType; object obj; try { obj = ICollectionExtensions.GetPropertyValue <T>(pro, strType, bitType, proType, value); if (obj != null) { pro.SetValue(t, obj, null); } } catch (FormatException exc) { if (!allowError) { throw new FormatException("转换错误,属性名:" + pro.Name); } } //if (pro.PropertyType.IsEnum) //{ // int.TryParse(value, out tmpInt); // pro.SetValue(t, tmpInt, null); //} //else //{ // try // { // pro.SetValue(t, Convert.ChangeType(value, pro.PropertyType), null); // } // catch (FormatException exc) // { // throw new FormatException("转换错误,属性名:" + pro.Name); // } //} } } return((T)t); }
public new T Create <T>(T span, FrameworkElement coveringElement) where T : Span { ICollectionExtensions.AddRange(span.Inlines, Inlines.Select(i => i.Create(coveringElement))); return(base.Create(span, coveringElement)); }