Well, there are a few things.
Firstly, you do not just have an extension method , you have an iterator block extension method - what you get when you use a yield returncontract for automatic implementation IEnumerable<>.
, , ActiveAccounts() null IEnumerable<Account>. , , null IEnumerable. ,
return null , :
: . .
, , yield break yield return null. , , , , . , LINQ, .
, if( rep == null ) ActiveAccounts(), . , , - , , .
:
public static class AccountExt
{
public static IEnumerable<Account> ActiveAccounts( this AccountRep rep )
{
if( rep == null )
throw new ArgumentNullException( "rep" );
if( rep.IsInternational )
return null;
return ActiveAccountsImpl( rep );
}
private static IEnumerable<Account> ActiveAccountsImpl( AccountRep rep )
{
foreach( acc in rep.FetchAccounts() )
{
if( acc.IsActive )
yield return acc;
}
}
}
LINQ, Impl :
public static IEnumerable<Account> ActiveAccounts( this AccountRep rep )
{
if( rep == null )
throw new ArgumentNullException( "rep" );
if( rep.IsInternational )
return null;
return rep.FetchAccounts().Where( acc => acc.IsActive );
}
, .