I have 3 methods that are almost exactly identical:
protected DetachedCriteria GetAvailableFundIdsPerDataUniverse()
{
return GetAvailableIdsPerDataUniverse()
.SetProjection(LambdaProjection.Property<Fund>(f => f.Id));
}
protected DetachedCriteria GetAvailableCompanyIdsPerDataUniverse()
{
return GetAvailableIdsPerDataUniverse()
.SetProjection(LambdaProjection.Property<Fund>(f => f.Company.Id));
}
protected DetachedCriteria GetAvailableCategoryIdsPerDataUniverse()
{
return GetAvailableIdsPerDataUniverse()
.SetProjection(LambdaProjection.Property<Fund>(f => f.Category.Id));
}
where GetAvailableIdsPerDataUniverse()
is defined as:
protected DetachedCriteria GetAvailableIdsPerDataUniverse()
{
return DetachedCriteria.For<Fund>()
.SetFetchMode<Fund>(f => f.ShareClasses, FetchMode.Join)
.CreateCriteria<Fund>(f => f.ShareClasses)
.Add(LambdaSubquery.Property<ShareClass>(x => x.Id).In(GetAvailableShareClassIdsPerDataUniverse()))
.Add<ShareClass>(f => f.ExcludeFromFT == false);
}
For each method, the only difference is the expression that's used to select the data, i.e.
f => f.Id
, f => f.Company.Id
and f => f.Category.Id
Could somebody please tell me if it's possible to pass that those differences into GetAvailableIdsPerDataUniverse()
as a variable so I can have only 1 method instead of having 4?