I'm trying to better understand lambda expressions with generic methods, I have some code for opening a connection and getting some information from a session I frequently use.
My goal is to pass in a object of Type T which can then get data from the fixture inside the lambda expression.
protected T getDataFromFixture<T>(int fixture_id, TTFixture fixture, Func<T, T> lambda)
{
var fixtures = Session.AllFixtures;
fixture = fixtures.ContainsKey(fixture_id) ? fixtures[fixture_id] : null;
if (fixture != null)
{
return lambda(T);
}
return default(T);
}
Question is: How do I pass through a lambda function into the openConnectionWithFixtureObject which can access the fixture object and return as type T
something like..
string total;
TTFixture fixture;
openConnectionWithFixtureObject<StatTotalList>(_fixtureUid, fixture, (statTotalsForOverview) =>
{
total; = fixture.myTotal();
});
I don't think the logic is too far off, i'm just unfamiliar with Func<T,TResult>
and generics . Any assistance would be greatly appreciated!