I have this common code:
private bool DoItStartup(IReader reader, Type provider)
{
/// lots of common boiler plate code
/// like:
var abcProvider = reader.ReaderData as AbcProvider;
var xyzProvider = abcProvider.Provisions.FirstOrDefault<XyzProvider>(); // line 2
}
The above lines of code are there for like 50 or some providers, now Line 2 I want to basically do this:
var xyzProvider = abcProvider.Provisions.FirstOrDefault<typeOf(provider)>();
This doesn't work, possibly because xyzProvider
doesn't know it's type @ compile time? Not sure. But is there a similar pattern I can use. Otherwise I'm having to duplicate this cruft code 50 times :(