사용 HtmlPage.RegisterScriptableObject("Shell", serviceLocator.GetInstance<Shell>());
코드 계약은 ServiceLocator에 대해 null 경고를 제공합니다.
null 경고가 나타납니다. 이걸 어떻게 없앨 수 있습니까?
사용 HtmlPage.RegisterScriptableObject("Shell", serviceLocator.GetInstance<Shell>());
코드 계약은 ServiceLocator에 대해 null 경고를 제공합니다.
null 경고가 나타납니다. 이걸 어떻게 없앨 수 있습니까?
경고는 serviceLocator
이 Null입니까? 당신의 코드를 더 이상 보지 않고
Contract.Assume(serviceLocator != null);
을 넣을 수있는 (다른 계약 플레이에있을 수 있습니다 무엇의 아이디어를 얻을 수 있습니다).
아마도 serviceLocator.GetInstance<Shell>()
은 인스턴스를 찾을 수없는 경우 null을 반환합니다.
해당 상황에 대한 대체 제어 흐름을 제공하십시오.
var instance = serviceLocator.GetInstance<Shell>();
if (instance == null)
throw new InvalidOperationException("Shell instance is missing.");
HtmlPage.RegisterScriptableObject("Shell", instance);