narsil/Tanshu.Accounts.Contracts/Helper Functions/ReflectionHelper.cs

28 lines
801 B
C#
Raw Normal View History

using System.Reflection;
using Tanshu.Accounts.Entities;
namespace Tanshu.Common.Helpers
{
public enum VoucherFields
{
CreationDate,
LastEditDate,
Date,
BillID,
KotID
}
public static class ReflectionHelper
{
public static void SetValue(this Voucher voucher, VoucherFields field, object value)
{
var fi = typeof(Voucher).GetField(ConvertToCamelCaseUnderscore(field.ToString()), BindingFlags.NonPublic | BindingFlags.Instance);
if (fi != null)
fi.SetValue(voucher, value);
}
private static string ConvertToCamelCaseUnderscore(string propertyName)
{
return "_" + propertyName[0].ToString().ToLower() + propertyName.Substring(1);
}
}
}