여기 내 코드는 다음과 같습니다객체가 null의 경우 확인하는 방법
public static class SerializationUtil
{
public static string Serialize(object obj)
{
if (obj == null)
return string.Empty;
StringWriter writer = new StringWriter();
new System.Web.UI.LosFormatter().Serialize(writer, obj);
return writer.ToString();
}
public static object Deserialize(string data)
{
if (data == null)
return null;
return (new System.Web.UI.LosFormatter()).Deserialize(data);
}
}
오전 데 문제가 다음 obj가 null의 경우 나는 직렬화 메서드를 호출 할 때이 오류가 발생합니다. 그래서 obj 값이 null인지 아닌지 확인하고 싶습니다. 지금 내가 가지고있는 코드는 obj 값이 결코 null이 아닌지 검사 될 때처럼 작동하지 않습니다.
는 해결 :
난 정말 당신이 설명하는 것은 가능하다고 생각하지 않는다 답변
예외는 어디에서 던져 질까? 예외의 스택 추적을 가지고 있습니까? –
새로운 System.Web.UI.LosFormatter()에서 throw됩니다. Serialize (writer, obj); – Luke101
정확한 오류 메시지를 게시하십시오. –