ReSharperNullReferenceException
は、
WindowsIdentity windowsIdentity = new WindowsIdentity(WindowsIdentity.GetCurrent().Token);
MSDN doc を調べましたが、これについての言及はありませんでした。また、実行可能ファイルを実行する場合はログオンする必要があるため、意味がありません。
これは単なる ReSharper 検索パターンですか?
ReSharperNullReferenceException
は、
WindowsIdentity windowsIdentity = new WindowsIdentity(WindowsIdentity.GetCurrent().Token);
MSDN doc を調べましたが、これについての言及はありませんでした。また、実行可能ファイルを実行する場合はログオンする必要があるため、意味がありません。
これは単なる ReSharper 検索パターンですか?
ILSpy を使用するGetCurrent
とGetCurrentInternal
、と を逆コンパイルしたバージョンを確認できますGetCurrent
。
GetCurrent:
public static WindowsIdentity GetCurrent()
{
return WindowsIdentity.GetCurrentInternal(TokenAccessLevels.MaximumAllowed, false);
}
GetCurrentInternal:
internal static WindowsIdentity GetCurrentInternal(TokenAccessLevels desiredAccess, bool threadOnly)
{
int errorCode = 0;
bool flag;
SafeTokenHandle currentToken = WindowsIdentity.GetCurrentToken(desiredAccess, threadOnly, out flag, out errorCode);
if (currentToken != null && !currentToken.IsInvalid)
{
WindowsIdentity windowsIdentity = new WindowsIdentity();
windowsIdentity.m_safeTokenHandle.Dispose();
windowsIdentity.m_safeTokenHandle = currentToken;
return windowsIdentity;
}
if (threadOnly && !flag)
{
return null;
}
throw new SecurityException(Win32Native.GetMessage(errorCode));
}
からthreadOnly
呼び出すときは常に falseGetCurrent
でありcurrentToken
、他の return ステートメントに対して有効でなければならないため、 null を取得するリスクはないと思いますWindowsIdentity
。
分解による、null
返品可能。
見る:GetCurrentInternal(TokenAccessLevels desiredAccess, bool threadOnly)
免責事項:私は特定の状態を分析するのが面倒です:)