Background and Motivation
As it is a best practice for API's to return ReadOnlyCollection<T> instead of List<T> etc, it would be nice to have an easy way to create an empty ReadOnlyCollection<T>. On par with Array.Empty<T>().
As it is also a best practice to return an empty collection instead of null.
Proposed API
public class ReadOnlyCollection<T>
{
public static ReadOnlyCollection<T> Empty { get; }
}
Usage Examples
public ReadOnlyCollection<Stuff> FindStuff(string filter)
{
if (string.IsNullOrEmpty(filter)) return ReadOnlyCollection<Stuff>.Empty;
}
Background and Motivation
As it is a best practice for API's to return
ReadOnlyCollection<T>instead ofList<T>etc, it would be nice to have an easy way to create an emptyReadOnlyCollection<T>. On par withArray.Empty<T>().As it is also a best practice to return an empty collection instead of null.
Proposed API
Usage Examples