public void GetMethodParameters(MethodDeclarationSyntax methodDeclaration, SemanticModel semanticModel, ControllerActionModel controllerActionModel, Compilation compilation) { var list = methodDeclaration.AttributeLists.SelectMany(a => a.Attributes).ToList(); var parameters = new List <ControllerActionParameter>(); var parameterListSyntax = methodDeclaration.ChildNodes().OfType <ParameterListSyntax>().FirstOrDefault(); foreach (var parameterSyntax in parameterListSyntax.Parameters) { var symbol = semanticModel.GetDeclaredSymbol(parameterSyntax); if (symbol == null) { continue; } var type = symbol.Type as INamedTypeSymbol; if (type == null) { continue; } var controllerParameter = new ControllerActionParameter { ParameterName = parameterSyntax.Identifier.ValueText, Required = !symbol.HasExplicitDefaultValue, ParameterTypeName = type.ToString(), ParameterTypeNamespace = type.ContainingNamespace.ToString() }; if (type.ContainingNamespace.IsGlobalNamespace) { //var location = type.Locations.FirstOrDefault(); //var tree = location?.SourceTree; //var root = tree.GetCompilationUnitRoot(); //var model = compilation.GetSemanticModel(tree); //var ns = GetNamespace(root); //controllerParameter.ParameterTypeNamespace = GetNamespace(root); } parameters.Add(controllerParameter); //var blockMethodParameter = BlockFactory.ParameterProvider.BlockMethodParameterFromMethodDeclaration(parameterSyntax, semanticModel, blockMethod); //if (blockMethodParameter != null) //{ // blockMethod.Parameters.Add(blockMethodParameter); //} } controllerActionModel.Parameters = parameters; }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { try { var controllersClasses = ClassesMetadata.GetClasses().ToList(); List <ControllerType> controllers = new List <ControllerType>(); foreach (var cnrtclass in controllersClasses) { try { var newCnt = new ControllerType(); newCnt.Name = cnrtclass.Name; newCnt.Functions = new List <ControllerAction>(); #region Functions var funcClass = cnrtclass.Children.OfType <CodeFunction2>().Where(func => func.Access == vsCMAccess.vsCMAccessPublic && func.FunctionKind == vsCMFunction.vsCMFunctionFunction).ToList(); foreach (var fun in funcClass) { try { var newCntaction = new ControllerAction(); newCntaction.Name = fun.Name; newCntaction.ControllerName = newCnt.Name; newCntaction.Name = fun.Name; newCntaction.returnType = (fun.Type?.CodeType as CodeClass2)?.Name ?? "void"; newCntaction.ActionVerb = GetVerb(fun); newCntaction.Parameters = new List <ControllerActionParameter>(); var funParams = fun.Parameters.OfType <CodeParameter2>()?.ToList(); foreach (var prm in funParams) { try { ControllerActionParameter p = new ControllerActionParameter() { Name = prm.Name, TypeName = prm?.Type?.CodeType?.Name }; newCntaction.Parameters.Add(p); } catch (Exception e1) { }; } newCnt.Functions.Add(newCntaction); } catch (Exception e2) { } } #endregion controllers.Add(newCnt); } catch (Exception e3) { } } IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell)); uiShell.EnableModeless(0); var xamlDialog = new ActionSelectorDialogWindow(controllers, InsertText) { Owner = Application.Current.MainWindow }; xamlDialog.HasMinimizeButton = false; xamlDialog.HasMaximizeButton = true; xamlDialog.MaxHeight = 440; xamlDialog.MinHeight = 340; xamlDialog.MaxWidth = 800; xamlDialog.MinWidth = 300; xamlDialog.Title = "Generate From Action"; xamlDialog.ActionToClose = xamlDialog.Close; xamlDialog.ShowDialog(); uiShell.EnableModeless(1); } catch (Exception ex) { } }