I know this question sounds like it could be a duplicate, but I could not find anything related to what I am about to describe.
I am trying to build an html email templating project. I have a viewmodel (only calling them that for clarity that they are simply classes with properties necessary for that email to pass the values that need to be replaced in the template)
public class EmailViewModels
{
public class AccountClosedEmailViewModel
{
public string Fullname { get; set; }
public string ApplicationName { get; set; }
public string Username { get; set; }
public string RenewRegistrationUrl { get; set; }
}
public class AccountReopenedEmailViewModel
{
public string Fullname { get; set; }
public string ApplicationName { get; set; }
public string Username { get; set; }
public string RenewRegistrationUrl { get; set; }
public string CancelVerificationUrl { get; set; }
}
public class ContactFormEmailViewModel
{
public string Fullname { get; set; }
public string ApplicationName { get; set; }
}
//rest removed for brevity
}
I want a method that takes an email view model, it could be any of those defined in the class above so I have a generic method to eliminate me having a BuildHtmlFromTemplate for each view model type.
public string BuildHtmlFromTemplate(templateFilePath, passing any one of the email viewmodels defined in the class)
{
var temp = File.IO.ReadAllText(templateFilePath);
temp.Replace("{username}", modelipassedin.username);
//do rest
return temp;
}
Is this possible?
object... but we don't know what the method is meant to do - what the code looks like. You could use reflection to find the properties, for example.BuildHtmlFromTemplate<T>(T o)