using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTask
{
public class ContractDataRecord
{
public string Name { get; set; }
public string Age { get; set; }
public string GuaranteeCost { get; set; }
public string GuaranteeCostChinese { get; set; }
public string GuaranteeTotal { get; set; }
public string MonthlyRepay { get; set; }
public string MonthlyRepayChinese { get; set; }
public string MothlyInterest { get; set; }
public string MontlyPrinciple { get; set; }
public string ServiceCost { get; set; }
public string AdvanceToB { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
namespace TestTask
{
public class AssembleContractData
{
static Dictionary<string, string> ComputeData = new Dictionary<string, string>{
{"GuaranteeCost","50"},
{"GuaranteeTotal","100"},
{"MonthlyRepay","200"},
{"MothlyInterest","400"},
{"AdvanceToB","500"},
};
public static ContractDataRecord BuildContractData()
{
ContractDataRecord data = new ContractDataRecord()
{
Name = "Smile",
};
if (ComputeData != null && ComputeData.Any())
{
var type = data.GetType();
foreach (var item in ComputeData.Keys)
{
try
{
var field = type.GetProperty(item);
if (field != null)
{
field.SetValue(data, ComputeData[item]);
var fieldChinese = type.GetProperty(item + "Chinese");
if (fieldChinese != null)
{
fieldChinese.SetValue(data, ComputeData[item] + "Chinese");
}
}
}
catch (Exception)
{
throw;
}
}
}
return data;
}
}
}