Vorrei ottenere un elenco di tutti i metodi pubblici nel mio progetto che sono decorati utilizzando MyAttribute
utilizzando T4/EnvDTE.Ottieni tutti i metodi decorati con un attributo specifico utilizzando T4/EnvDTE
So che questo può essere fatto con la riflessione, ma non voglio caricare l'assembly e riflettere su di esso in un modello T4, piuttosto, voglio usare i file di codice esistenti come sorgente.
Quello che segue è codice standard che ho trovato su internet che ottiene un riferimento al progetto corrente
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Core.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
<#
IServiceProvider _ServiceProvider = (IServiceProvider)Host;
if (_ServiceProvider == null)
throw new Exception("Host property returned unexpected value (null)");
EnvDTE.DTE dte = (EnvDTE.DTE)_ServiceProvider.GetService(typeof(EnvDTE.DTE));
if (dte == null)
throw new Exception("Unable to retrieve EnvDTE.DTE");
Array activeSolutionProjects = (Array)dte.ActiveSolutionProjects;
if (activeSolutionProjects == null)
throw new Exception("DTE.ActiveSolutionProjects returned null");
EnvDTE.Project dteProject = (EnvDTE.Project)activeSolutionProjects.GetValue(0);
if (dteProject == null)
throw new Exception("DTE.ActiveSolutionProjects[0] returned null");
#>
Non vedo "tangibile Automazione di Visual Studio Helper" nell'elenco dei modelli di VS. – Omar
Lo vedo ora. Devi aprire un file '.tt' a quel punto comparirà il menu' Tangibile T4' con i menu standard. È la prima voce di menu. Lasciami fare un tentativo. – Omar
Riesco a vedere Visual Studio Automation Helper nel modello Gallary ma non vi è alcun riferimento a VisualStudioHelper. Esiste una classe chiamata DteHelper ma non ha i metodi indicati nel tuo esempio come GetAllCodeElementsOfType. –