public static U GetValueSafe <T, U>(this EntityCollection <T> items, int index, Func <T, U> getValueFunc, U defaultValue = default(U)) where T : class { var p = items.ElementAtOrDefault(index); if (p != null) { return(getValueFunc(p)); } return(defaultValue); }