Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想编写一个通用方法,它接受任何类型的类对象并为该对象的所有属性返回一个 keyValuepair。
public Dictionary<string,string> GetProperties(T classObj) { }
对此的任何帮助将非常有用。
使用反射:
public Dictionary<string, object> GetProperties<T>(T classObj) { return typeof(T).GetProperties() .ToDictionary(p => p.Name, p => p.GetValue(classObj, null)); }