Accessing C# property name or attributes

前端 未结 7 2130
花落未央
花落未央 2021-01-31 21:39

I would like to automatically generate SQL statements from a class instance. The method should look like Update(object[] Properties, object PrimaryKeyProperty). The method is pa

7条回答
  •  遥遥无期
    2021-01-31 21:54

    You can do something like this:

    Type t = someInstance.getType();
    
    foreach (MemberInfo mi in t.GetMembers())
    {
        if (mi.MemberType == MemberTypes.Property)
        {
            Console.WriteLine(mi.Name);
        }
    }
    

    to get all the property names for instance's type.

提交回复
热议问题