【发布时间】:2014-03-18 03:06:43
【问题描述】:
我想从类实例中自动生成 SQL 语句。该方法应类似于 Update(object[] Properties, object PrimaryKeyProperty)。该方法是实例的一部分(类,基方法 - 任何孩子的通用方法)。属性数组是一个类属性数组,将在 update 语句中使用。属性名称等于表字段名称。
问题是我无法获取属性名称。
是否有任何选项可以在类实例中获取属性名称? 示例:
public class MyClass {
public int iMyProperty { get; set; }
public string cMyProperty2 { get; set; }
{
main() {
MyClass _main = new MyClass();
_main.iMyProperty.*PropertyName* // should return string "iMyProperty"
{
我知道 PropertyInfo,但我不知道如何从 GetProperties() 数组中获取属性的 ID。
有什么建议吗?
【问题讨论】:
标签: c# properties