private void MenuItemCallback(object sender, EventArgs e) { var injectDependencyCaption = "Inject Dependency"; if (_dte.ActiveDocument == null) { DialogHelpers.Error("Open a code file first.", injectDependencyCaption); return; } using (var injectDependencyDialog = new InjectDependencyDialog( _fieldNameGenerators, _dependencyNameProviders, _dependencyInjector.GetExpectedClassName(_dte.ActiveDocument))) { if (injectDependencyDialog.ShowDialog() == DialogResult.OK) { var dependencyInjectionData = injectDependencyDialog.GetDependencyInjectionData(); if (string.IsNullOrEmpty(dependencyInjectionData.FieldName) || string.IsNullOrEmpty(dependencyInjectionData.FieldType) || string.IsNullOrEmpty(dependencyInjectionData.ConstructorParameterName) || string.IsNullOrEmpty(dependencyInjectionData.ConstructorParameterType)) { DialogHelpers.Warning("Field and constructor parameter names and types must be filled.", injectDependencyCaption); return; } var result = _dependencyInjector.Inject( _dte.ActiveDocument, injectDependencyDialog.GetDependencyInjectionData()); if (!result.Success) { switch (result.ErrorCode) { case DependencyInjectorErrorCodes.ClassNotFound: DialogHelpers.Warning( "Could not inject dependency because the class was not found in this file.", injectDependencyCaption); break; default: DialogHelpers.Warning("Could not inject dependency.", injectDependencyCaption); break; } } } } }