public ReportElements.StepDefinitionReport GenerateReport()
        {
            report = new ReportElements.StepDefinitionReport();
            report.ProjectName = specFlowProject.ProjectName;
            report.GeneratedAt = DateTime.Now.ToString("g", CultureInfo.InvariantCulture);
            report.ShowBindingsWithoutInsance = ReportParameters.ShowBindingsWithoutInsance;

            stepDefByBinding = new Dictionary<BindingInfo, StepDefinition>();
            bindingByStepDef = new Dictionary<StepDefinition, BindingInfo>();

            foreach (var bindingInfo in bindings)
            {
                var stepDefinition = new StepDefinition();
                stepDefinition.Binding = new Binding { MethodReference = bindingInfo.MethodReference };
                stepDefinition.Type = bindingInfo.BindingType;

                stepDefByBinding.Add(bindingInfo, stepDefinition);
                bindingByStepDef.Add(stepDefinition, bindingInfo);
                report.StepDefinitions.Add(stepDefinition);
            }

            foreach (var feature in parsedFeatures)
            {
                var featureRef = new FeatureRef { FilePath = feature.SourceFile, Name = feature.Title };
                if (feature.Background != null)
                {
                    var scenarioRef = new ScenarioRef { Name = "Background" };
                    AddStepInstances(featureRef, scenarioRef, feature.Background.Steps, false);
                }

                foreach (var scenario in feature.Scenarios)
                {
                    var scenarioRef = new ScenarioRef { Name = scenario.Title, SourceFileLine = scenario.FilePosition == null ? -1 : scenario.FilePosition.Line };
                    if (scenario is ScenarioOutline)
                    {
                        ScenarioSteps firstExampleSteps = CreateFirstExampleScenarioSteps((ScenarioOutline) scenario);
                        AddStepInstances(featureRef, scenarioRef, firstExampleSteps, true);
                    }
                    else
                    {
                        AddStepInstances(featureRef, scenarioRef, scenario.Steps, false);
                    }
                }
            }

            foreach (var stepDefinition in report.StepDefinitions)
            {
                if (stepDefinition.ScenarioStep == null)
                {
                    CreateSampleStep(stepDefinition);
                }
                
                if (stepDefinition.Instances.Count == 0)
                {
                    stepDefinition.Instances = null;
                }
            }

            return report;
        }
        private void AddStepInstances(FeatureRef featureRef, ScenarioRef scenarioRef, IEnumerable<ScenarioStep> scenarioSteps, bool fromScenarioOutline)
        {
            string currentBlock = "";

            foreach (var scenarioStep in scenarioSteps)
            {
                if (scenarioStep is Given || scenarioStep is When || scenarioStep is Then)
                    currentBlock = scenarioStep.GetType().Name;

                bool found = false;

                foreach (var bindingInfo in bindings)
                {
                    if (bindingInfo.BindingType != currentBlock)
                        continue;

                    var match = bindingInfo.Regex.Match(scenarioStep.Text);
                    if (!match.Success)
                        continue;

                    Instance instance = new Instance
                                            {
                                                FromScenarioOutline = fromScenarioOutline,
                                                ScenarioStep = scenarioStep,
                                                FeatureRef = featureRef,
                                                ScenarioRef = scenarioRef
                                            };
                    var regexArgs = match.Groups.Cast<Group>().Skip(1).Select(g => g.Value).ToArray();
                    if (regexArgs.Length > 0)
                    {
                        instance.Parameters = new List<Parameter>();
                        for (int i = 0; i < Math.Min(regexArgs.Length, bindingInfo.ParameterNames.Length); i++)
                            instance.Parameters.Add(new Parameter { Name = bindingInfo.ParameterNames[i], Value = regexArgs[i] });
                    }

                    var stepDefinition = stepDefByBinding[bindingInfo];
                    stepDefinition.Instances.Add(instance);

                    if (stepDefinition.ScenarioStep == null)
                    {
                        stepDefinition.ScenarioStep = CloneTo(scenarioStep, currentBlock);
                        stepDefinition.ScenarioStep.Text = GetSampleText(bindingInfo, stepDefinition.ScenarioStep.Text, match);
                    }

                    found = true;
                    break;
                }

                if (!found)
                {
                    var stepDefinition =
                        stepDefsWithNoBinding.FirstOrDefault(sd => sd.ScenarioStep.Text.Equals(scenarioStep.Text));

                    if (stepDefinition == null)
                    {
                        stepDefinition = new StepDefinition();
                        stepDefinition.Type = currentBlock;
                        stepDefinition.ScenarioStep = CloneTo(scenarioStep, currentBlock);
                        stepDefsWithNoBinding.Add(stepDefinition);
                        report.StepDefinitions.Add(stepDefinition);
                    }

                    Instance instance = new Instance
                                            {
                                                FromScenarioOutline = fromScenarioOutline,
                                                ScenarioStep = scenarioStep,
                                                FeatureRef = featureRef,
                                                ScenarioRef = scenarioRef
                                            };
                    stepDefinition.Instances.Add(instance);
                }
            }
        }
        public ReportElements.StepDefinitionReport GenerateReport()
        {
            report = new ReportElements.StepDefinitionReport();
            report.ProjectName = specFlowProject.ProjectSettings.ProjectName;
            report.GeneratedAt = DateTime.Now.ToString("g", CultureInfo.InvariantCulture);
            report.ShowBindingsWithoutInsance = ReportParameters.ShowBindingsWithoutInsance;

            stepDefByBinding = new Dictionary<BindingInfo, StepDefinition>();
            bindingByStepDef = new Dictionary<StepDefinition, BindingInfo>();

            foreach (var bindingInfo in bindings)
            {
                var stepDefinition = new StepDefinition();
                stepDefinition.Binding = new Binding { MethodReference = bindingInfo.MethodReference };
                stepDefinition.Type = bindingInfo.BindingType;

                stepDefByBinding.Add(bindingInfo, stepDefinition);
                bindingByStepDef.Add(stepDefinition, bindingInfo);
                report.StepDefinitions.Add(stepDefinition);
            }

            foreach (var specflowDocument in parsedSpecFlowDocuments)
            {
                var feature = specflowDocument.SpecFlowFeature;
                var featureRef = new FeatureRef { FilePath = specflowDocument.SourceFilePath, Name = feature.Name };
                if (feature.Background != null)
                {
                    var scenarioRef = new ScenarioRef { Name = "Background" };
                    AddStepInstances(featureRef, scenarioRef, feature.Background.Steps, false);
                }

                foreach (var scenario in feature.ScenarioDefinitions)
                {
                    var scenarioRef = new ScenarioRef { Name = scenario.Name, SourceFileLine = scenario.Location == null ? -1 : scenario.Location.Line };
                    if (scenario is ScenarioOutline)
                    {
                        var firstExampleSteps = CreateFirstExampleScenarioSteps((ScenarioOutline) scenario);
                        AddStepInstances(featureRef, scenarioRef, firstExampleSteps, true);
                    }
                    else
                    {
                        AddStepInstances(featureRef, scenarioRef, scenario.Steps, false);
                    }
                }
            }

            foreach (var stepDefinition in report.StepDefinitions)
            {
                if (stepDefinition.ScenarioStep == null)
                {
                    CreateSampleStep(stepDefinition);
                }

                if (stepDefinition.Instances.Count == 0)
                {
                    stepDefinition.Instances = null;
                }

                //if(stepDefinition.ScenarioStep.ScenarioBlock == 0)
                //{
                //    stepDefinition.ScenarioStep.ScenarioBlock = (Parser.ScenarioBlock)Enum.Parse(typeof (Parser.ScenarioBlock), stepDefinition.Type);
                //}

                //if(stepDefinition.ScenarioStep.StepKeyword == 0)
                //{
                //    stepDefinition.ScenarioStep.StepKeyword = (StepKeyword)Enum.Parse(typeof(StepKeyword), stepDefinition.Type);
                //}
            }

            return report;
        }