[.NET]PropertyInfo

해내면 그만!XX·2022년 5월 22일
0

PropertyInfo class
: 제네릭 타입의 클래스의 필드 혹은 프로퍼티에 접근해야할 때가 있다.
그러나 타입을 정확히 모르기 때문에 직접 접근할 수는 없는데 이를 해결하는 것이 PropertyInfo이다.

foreach (PropertyInfo propertyInfo in data.GetType().GetProperties())
//PropertyInfo.PropertyType속성의 유형을 가져 오는 데 사용 합니다.
public static bool IsStringType(object data)
{
	return (data.GetType().GetProperties().Where(x => x.PropertyType == typeof(string)).FirstOrDefault() != null);
}

참조
https://debuglog.tistory.com/51
http://daplus.net/c-propertyinfo%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC-%EC%86%8D%EC%84%B1-%EC%9C%A0%ED%98%95-%EC%B0%BE%EA%B8%B0/

0개의 댓글