Read class methods properties in mvc4 T4 template
i am working on T4 Templates in web api project in ASP.Net MVC3. i need to
get classes and methods from business layer and create cs files using .tt
files. also i aneed to get methods only have [PrivateApi] tag.
this is my t4 template class.
<#
Assembly ab = AppDomain.CurrentDomain.GetAssemblies()
.Where(b=>b.GetName().Name.Trim().ToLower() ==
"Empite.Give360.Business".ToLower())
.FirstOrDefault() as Assembly;
foreach (var type in ab.GetTypes())
{
if (type.Name.EndsWith("Service") && type.IsInterface )
{
CreateAPI(type);
SaveOutput(type.Name + "API.cs");
}
}
DeleteOldOutputs(); #>
<#+ public void CreateAPI(Type businessObjType ) {#>
public class <#= businessObjType.Name.Substring(1) #>API : <#=
businessObjType.Name #>API { } public interface <#= businessObjType.Name
#>API { } <#+ } #>
this is generated CS file
public class DonationServiceAPI : IDonationServiceAPI
{
}
public interface IDonationServiceAPI
{
}
This is the class that i need to reproduce
public class DonationService : IDonationService
{
private readonly IDonationRepository _donationRepository;
private readonly IDonationStatusTypeRepository
_donationStatusTypeRepository;
private readonly IPayrollDeductionRepository
_payrollDeductionRepository;
public DonationService() : this(new DonationRepository(),new
DonationStatusTypeRepository(),new PayrollDeductionRepository())
{
}
public DonationService(IDonationRepository
donationRepository,IDonationStatusTypeRepository
donationStatusTypeRepository,IPayrollDeductionRepository
payrollDeductionRepository)
{
_donationRepository = donationRepository;
_donationStatusTypeRepository = donationStatusTypeRepository;
_payrollDeductionRepository = payrollDeductionRepository;
}
[PrivateApi]
public ServiceResponse<Donation> GetDonationByDonationId(int donationId)
{
var donationObj = _donationRepository.Get(donationId);
return new ServiceResponse<Donation>(donationObj);
}
}
i'm new comer to T4 Templates and Does anyone know how to do so?
No comments:
Post a Comment