【发布时间】:2014-04-01 00:35:35
【问题描述】:
目前我有一个有很多自动属性类的类,如下所示。
class SQLiteTables
{
public class tbl_account_codes
{
[PrimaryKey, AutoIncrement]
public int ACCT_ID { get; set; }
public string ACCT_CODE { get; set; }
public string ACCT_DESC { get; set; }
public string FUND_CODE { get; set; }
public string ROR_FLAG { get; set; }
public string OR_FLAG { get; set; }
public string AR_FLAG { get; set; }
public DateTime CREATED_DATE { get; set; }
public string CREATED_BY { get; set; }
public Nullable<DateTime> LAST_MODIFIED_DATE { get; set; }
public string LAST_MODIFIED_BY { get; set; }
public string ACCT_STATUS { get; set; }
}
public class tbl_ack_receipt
{
[PrimaryKey, AutoIncrement]
public int AR_ID { get; set; }
public string TPAY_RECEIPT_NO { get; set; }
public string TPAY_SIG_ALGO { get; set; }
public string BFNS_CODE { get; set; }
public string TAXT_CODE { get; set; }
public string ACCT_CODE { get; set; }
public DateTime AR_PERIOD_COVERED { get; set; }
public Nullable<int> AR_QUARTER { get; set; }
public string AR_ASSESSMENT_NO { get; set; }
public Nullable<DateTime> AR_DUE_DATE { get; set; }
public string RFNP_CODE { get; set; }
public string RFNP_OTHER { get; set; }
public decimal AR_BASIC_TAX { get; set; }
public decimal AR_SURCHARGE { get; set; }
public decimal AR_INTEREST { get; set; }
public decimal AR_TOTAL_DUE { get; set; }
public decimal AR_TOTAL_PAID { get; set; }
public string MPAY_CODE { get; set; }
public string TYPEP_CODE { get; set; }
public string AR_REMARKS { get; set; }
public string AR_STATUS { get; set; }
public decimal AR_COMPROMISE { get; set; }
}
public class tbl_agency_codes
{
[PrimaryKey, AutoIncrement]
public int AGENCY_ID { get; set; }
public string AGENCY_CODE { get; set; }
public string AGENCY_DESC { get; set; }
public DateTime CREATED_DATE { get; set; }
public string CREATED_BY { get; set; }
public Nullable<DateTime> LAST_MODIFIED_DATE { get; set; }
public string LAST_MODIFIED_BY { get; set; }
public string AGENCY_STATUS { get; set; }
}
}
每次我想从类中检索特定属性时,我都需要这样做。
var qry = conn.Table<Tbl.tbl_agency_codes>().Where(x => x.AGENCY_CODE.StartsWith("0605"));
不用说,写几十个是很累的。所以我想知道是否可以简化它并制作一个类似的方法。
private void ThisMethod<T>(SomeProperty SomeProperty)
{
var qry = conn.Table<T>().Where(x => x.SomeProperty.StartsWith("Something"));
}
这可能吗?
【问题讨论】:
-
你可以使用反射
-
你明白吗,如果重命名某些属性,你的代码会被无声地破坏?
标签: c# .net methods properties parameters