I have the following Interfaces defined:
public interface IStep
{
string Name { get; set; }
}
public interface IStepBuildDataSet : IStep
{
DataSet
You could use OfType to make it abit cleaner like this:
IStepBuildDataSet buildDataSet = Steps.OfType<IStepBuildDataSet>().Single();
IStepBuildFile buildFile = Steps.OfType<IStepBuildFile>().Single();
Notice, you dont need to cast the results, since OfType does that for you.
You have list of IStep, so there could be more than one of different types of Istep objects in the list. so it's better to do it in the foreach loop.
foreach(IStepBuildDataSet buildDataSet in Steps.OfType<IStepBuildDataSet>())
{
//do something here.
}
foreach(IStepBuildFile buildFile in Steps.OfType<IStepBuildFile>())
{
//do something here.
}