Extension method signature
Provide the full method signature here, without parameter names, but do not include the leading this T x parameter. Example:
T[] AsArray<T>(this T value)
// and
IEnumerable<T> AsEnumerable<T>(this T value)
Parameters
Parameter
Type
Description
value
T
The value to encapsulate.
Description
Encapsulates the value into an array of length 1 containing the value.
or
Yields the value into an IEnumerable<T> with one element.
Benefits
To save having to encapsulate as new Foo[] { myFoo } when object is known singleton where array is expected, myFoo.AsArray() or myFoo.AsEnumerable() allows for contiguous method chaining.
DrawbacksAsEnumerable could conflict with LINQ's AsEnumerable, this may be something to consider.
(Optional) Implementation example
{
return new[] {value};
// or
yield return value;
}
Type
Extension method signature Provide the full method signature here, without parameter names, but do not include the leading
this T x
parameter. Example:T
Description Encapsulates the value into an array of length 1 containing the value. or Yields the value into an
IEnumerable<T>
with one element.Benefits To save having to encapsulate as
new Foo[] { myFoo }
when object is known singleton where array is expected,myFoo.AsArray()
ormyFoo.AsEnumerable()
allows for contiguous method chaining.Drawbacks
AsEnumerable
could conflict with LINQ's AsEnumerable, this may be something to consider.(Optional) Implementation example