I have a class as below
public class Details
{
public string CreatedAt {set;get;)
public Order Order { get; set; }
public Customer Customer { get; set; }
}
public class Customer
{
public string Name { get; set; }
public CustomerAddress Address { get; set; }
}
public class CustomerAddress
{
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
public string State { get; set; }
}
and I have HTML file with HTML content and few placeholder. I am replacing placeholders as below.
public static string ReplaceStringPlaceHolders(User Details)
{
string MyHTML= File.ReadAllText(@"...Path");
//Replacing one by one
string newstring= MyHTML.
.Replace("{created_at}", Details.CreatedAt)
.Replace("{customer_info.address.line_1}", Details.Customer.Address.Line1)
.Replace("{customer_info.address.line_2}", Details.Customer.Address.Line2)
.Replace("{customer_info.address.city}", Details.Customer.Address.City)
.Replace("{customer_info.address.state}", Details.Customer.Address.State)
.Replace("{customer_info.address.postal_code}", Details.Customer.Address.PostalCode)
.Replace("{customer_info.address.country}", Details.Customer.Address.Country)
return newstring;
}
but I don't like this way as I have put 50+ placeholders in my HTML file. Is there a way that we can replace the placeholder when the placeholder name matches to class properties.
I am looking for something like this if possible:
MyHTML.replaceifPlaceHolderMatchesWithClassProperties(Label);
Kindly suggest.