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)); }