I am currently creating a few templates for my team to use within various projects.
I have a very simple "simple mapper" template and a wizard to go along with it that I'd like to expand adding others as I continue.
namespace $rootnamespace$;
public class $safeitemname$
{
public $mapto$ Map($mapfrom$ entity)
{
return new $mapto$()
{
Id = entity.Id,
Name = entity.Name
};
}
public $mapfrom$ MapToDb($mapto$ item)
{
return new $mapfrom$()
{
Id = item.Id,
Name = item.Name
};
}
}
$mapto$ is replaced with the user's input.
I would like to know if it's possible to look through the hosts solution, get the properties of a class referenced there (e.g. $mapto$) and use this to default the mapping. Is this possible with item templates?
I have seen some reference to T4 templates and will be looking in to those, but would like to know if it's possible with the basic item templates.
I tested in VS2022 by adding
CustomParameter elementinto vstemplate file for the template and it can get the properties of a class referenced in current project or current solution. After you create an item template, the files for the template are added to a .zip file.The default location is %USERPROFILE%\Documents\Visual Studio \My Exported Templates. Edit thevstemplate fileand add custom parameters into the file.example