내가 보려고 기록하는것

C#) get property value from string using reflection

디리릭 2022. 4. 27. 16:55
728x90
 public static object GetPropValue(object src, string propName)
 {
     return src.GetType().GetProperty(propName).GetValue(src, null);
 }

 

 

         string result = "";
                    for (int pos = 0; pos < optionList.Count(); pos++)
                    {
                        var propName = $"optionName{pos+1}";

                        result += displayOptionIndx[pos] == 1 ? " "+GetPropValue(s, propName) : "";
                    }
728x90

'내가 보려고 기록하는것' 카테고리의 다른 글

[linux] 기본 명령어 정리  (0) 2022.09.12
WSL 재설치  (0) 2022.05.02
NLP, custom modeling with Spacy  (0) 2022.03.10
NLP 라이브러리  (0) 2022.03.10
구글 시트에 데이터 json으로 받기  (0) 2021.11.09