String Format object extension I wrote an extension to create a string-representation by an object:

public static string ToString&lt;T&gt;(this T @this, Func&lt;T, string&gt; predicate) where T: class
{
    return predicate(@this);
}


So I can do something like 

return handler.GetUserById(id)?.ToString(x =&gt; $"{x.LastName}, {x.FirstName}");


which gives me either null if the user is null or otherwise e.g. "Miller, Peter" 

My question: is this a good extension? Makes it sense? Anything I didn't consider?
And what about the null-thing? Should I check the null value in the extension? Imho, the thrown NullReferenceException is okay, if s.o. calls this with a null object.
There are not much to review, so to answer your questions:


It's a good extension if you can see it useful in more than one place.
It makes sense.
I can't see anything else to consider - a null check on the predicate maybe?
If the exception thrown by the predicate when @this is null is good enough for you, don't bother further.




I don't see why the restriction where T: class is necessary



If you always want to generate a string containing a list of properties (or another predefined format), you could change the signature to:

public static string ToString&lt;T&gt;(this T @this, params Func&lt;T, object&gt;[] getters)
{
  return string.Join(", ", getters.Select(g =&gt; g(@this)));
}


called as:

handler.GetUserById(id)?.ToString(p =&gt; p.LastName, p =&gt; p.FirstName)


so that you don't have to format the input when calling the extension.