Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
We stumbled across
public static IEnumerable<TBase> ForAllThatAre<TBase, TActual>(this IEnumerable<TBase> sequence, Action<TActual> projection) where TActual : class;
which is an extension in the Umbraco.Core but cannot figure out what it does.
Can anyone shed some light please?
The implementation of this method can be found here.
Hope this helps
Thanks for replying but I'm still not sure what it actually does.
If you could post your usage of this method, I may be able to explain it in some context.
return sequence.Select( //Loop through each item in sequence
if (x is TActual) // If the current item TActual is derived from type TBase
var casted = x as TActual; // cast TBase to TActual
projection.Invoke(casted); // Invoke the action which you passed, passing our casted TActual as a parameter
return x; // Return the initial TBase
Basically what this method allows us to do is loop through a list of objects and invoke an Action for each item which is of a certain base type without amending the initial list.
The method is extremely generic which may have caused some confusion, but the above is a basic explanation of how it could be used.
Gary, thanks for getting back to me. I haven't used the method yet as I didn't know what to do with it. Am I right in saying that we could give it a collection of objects and sort them based on whether they are a string?
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted