Reputation: 297
Hi I need your help please. I have the following code:
public class CompensationProvider
{
private Func<List<Result_CompensationPolicy>, int> _EmployeeIdCount = (a =>
a.Where(t => !string.IsNullOrEmpty(t.EmployeeId))
.Select(x => x.EmployeeId)
.Distinct()
.Count());
private Func<List<Result_CompensationPolicy>, string, IEnumerable<HandlerCompanyCompensationSummery>> _GroupCompensationBalanceByHandler = ((compensationPolicy, managmentCompanyId) =>
(from p in compensationPolicy
where string.Compare(p.AccountIdentificationNumber, managmentCompanyId, true) == 0
group p by p.HandlerIdentificationNumber into g
select new HandlerCompanyCompensationSummery
{
AnsweringStatus = g.FirstOrDefault().AnswerStatus == (int)EventsAnsweringStatus.CompanySentFeedbackB ? g.FirstOrDefault().ErrorDescription : GetStstusText(g.FirstOrDefault().AnswerStatus),
AnsweringStatusId = (EventsAnsweringStatus)g.FirstOrDefault().AnswerStatus,
HandlerCompanyName = g.FirstOrDefault(m => !string.IsNullOrEmpty(m.ManufacturerName)).ManufacturerName,
HandlerCompanyId = g.FirstOrDefault(m => !string.IsNullOrEmpty(m.HandlerIdentificationNumber)).HandlerIdentificationNumber,
AllCompanyProducts = g.Where(p => p.AnswerStatus == (int)EventsAnsweringStatus.CompanySentInfo).Select(x => x.ProductType).Distinct(),
EmployeesIdCount = _EmployeeIdCount(g.ToList()),
PoliciesCount = _PoliciesCount(g.ToList()),
CompensationSum = _CompensationSum(g.ToList())
})
);
}
And in line EmployeesIdCount = _EmployeeIdCount(g.ToList()) I get this error: an object reference is required for the nonstatic field method or property.
Why? and do I have to make it static or there is another solution?
Thank you in advanced
Upvotes: 0
Views: 39
Reputation: 203834
You'll need to initialize the field from the constructor, if it needs to use the value of another field's initializer (which is what's going on here). You can't initialize that value when declaring it.
Upvotes: 2