리플렉션을 사용하여 nullable 부울 값을 처리하려고합니다. 값은 DB에서 오므로 동일하게 유지해야합니다.리플렉션을 사용하여 Nullable 부울 값 가져 오기
다음은 현재 사용중인 코드입니다.
내가bool? tempBool = (bool?)prop.GetValue(prop, null);
에서 브레이크 포인트를 넣어 라인을 실행하면
public partial class PrinterConfigUC : UserControl
{
prtsetup Printer { get; set; }
public PrinterConfigUC(prtsetup printer)
{
InitializeComponent();
this.Printer = printer;
lblPrinterName.Text = Printer.prtname;
var properties = printer.GetType().GetProperties();
foreach (var prop in properties)
{
//In debug, a nullable bool had a type name of "Nullable`1"
if (prop.PropertyType.Name.Equals("Nullable`1"))
{
bool? tempBool = (bool?)prop.GetValue(prop, null);
}
}
}
, 프로그램 추가 실행을 중지하고 그냥 나에게 빈의 WinForm을 보여줍니다. 다른 일은 일어나지 않습니다. 오류 메시지가없고 프로그램이 중단되지도 않고 한 줄에 멈춰 있습니다.
그 줄은'bool이 아니어야합니까? tempBool = (bool?) prop.GetValue (printer);'? – DavidG
DavidG가 맞습니다. 내가 할 수있는 한 아래의 답을 확인해 줄 것입니다. 도와 주셔서 감사합니다. 내 벙어리 실수. –