// The Debugger class is a part of the System.Diagnostics package
// and is used for communicating with a debugger.
+#nullable enable
using System.Runtime.CompilerServices;
namespace System.Diagnostics
// desired events are actually reported to the debugger.
//
// Constant representing the default category
- public static readonly string DefaultCategory = null;
+ public static readonly string? DefaultCategory = null;
// Posts a message for the attached debugger. If there is no
// debugger attached, has no effect. The debugger may or may not
// report the message depending on its settings.
[MethodImpl(MethodImplOptions.InternalCall)]
- public static extern void Log(int level, string category, string message);
+ public static extern void Log(int level, string? category, string? message);
// Checks to see if an attached debugger has logging enabled
//
**
=============================================================================*/
-
+#nullable enable
using System;
namespace System.Diagnostics
{
#pragma warning disable 169
#pragma warning disable 414 // Field is not used from managed.
- private object _objectReference;
+ private object? _objectReference;
#pragma warning restore 414
#pragma warning restore 169
}
**
===========================================================*/
+#nullable enable
using System;
namespace System.Diagnostics
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Text;
namespace System.Diagnostics
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
// VM\DebugDebugger.h. The binder will catch some of these layout problems.
internal class StackFrameHelper
{
- private Thread targetThread;
- private int[] rgiOffset;
- private int[] rgiILOffset;
+ private Thread? targetThread;
+ private int[]? rgiOffset;
+ private int[]? rgiILOffset;
#pragma warning disable 414
// dynamicMethods is an array of System.Resolver objects, used to keep
// DynamicMethodDescs AND collectible LoaderAllocators alive for the lifetime of StackFrameHelper.
- private object dynamicMethods; // Field is not used from managed.
-
- private IntPtr[] rgMethodHandle;
- private string[] rgAssemblyPath;
- private Assembly[] rgAssembly;
- private IntPtr[] rgLoadedPeAddress;
- private int[] rgiLoadedPeSize;
- private IntPtr[] rgInMemoryPdbAddress;
- private int[] rgiInMemoryPdbSize;
+ private object? dynamicMethods; // Field is not used from managed.
+
+ private IntPtr[]? rgMethodHandle;
+ private string[]? rgAssemblyPath;
+ private Assembly?[]? rgAssembly;
+ private IntPtr[]? rgLoadedPeAddress;
+ private int[]? rgiLoadedPeSize;
+ private IntPtr[]? rgInMemoryPdbAddress;
+ private int[]? rgiInMemoryPdbSize;
// if rgiMethodToken[i] == 0, then don't attempt to get the portable PDB source/info
- private int[] rgiMethodToken;
- private string[] rgFilename;
- private int[] rgiLineNumber;
- private int[] rgiColumnNumber;
- private bool[] rgiLastFrameFromForeignExceptionStackTrace;
+ private int[]? rgiMethodToken;
+ private string?[]? rgFilename;
+ private int[]? rgiLineNumber;
+ private int[]? rgiColumnNumber;
+ private bool[]? rgiLastFrameFromForeignExceptionStackTrace;
private int iFrameCount;
#pragma warning restore 414
- private delegate void GetSourceLineInfoDelegate(Assembly assembly, string assemblyPath, IntPtr loadedPeAddress,
+ private delegate void GetSourceLineInfoDelegate(Assembly? assembly, string assemblyPath, IntPtr loadedPeAddress,
int loadedPeSize, IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset,
- out string sourceFile, out int sourceLine, out int sourceColumn);
+ out string? sourceFile, out int sourceLine, out int sourceColumn);
- private static GetSourceLineInfoDelegate s_getSourceLineInfo = null;
+ private static GetSourceLineInfoDelegate? s_getSourceLineInfo = null;
[ThreadStatic]
private static int t_reentrancy = 0;
- public StackFrameHelper(Thread target)
+ public StackFrameHelper(Thread? target)
{
targetThread = target;
rgMethodHandle = null;
// rgiLineNumber and rgiColumnNumber fields using the portable PDB reader if not already
// done by GetStackFramesInternal (on Windows for old PDB format).
//
- internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception exception)
+ internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception? exception)
{
StackTrace.GetStackFramesInternal(this, iSkip, fNeedFileInfo, exception);
{
if (s_getSourceLineInfo == null)
{
- Type symbolsType = Type.GetType(
+ Type? symbolsType = Type.GetType(
"System.Diagnostics.StackTraceSymbols, System.Diagnostics.StackTrace, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
throwOnError: false);
typeof(int), typeof(int), typeof(int),
typeof(string).MakeByRefType(), typeof(int).MakeByRefType(), typeof(int).MakeByRefType()
};
- MethodInfo symbolsMethodInfo = symbolsType.GetMethod("GetSourceLineInfo", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameterTypes, null);
+ MethodInfo? symbolsMethodInfo = symbolsType.GetMethod("GetSourceLineInfo", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameterTypes, null);
if (symbolsMethodInfo == null)
{
return;
}
// Create an instance of System.Diagnostics.Stacktrace.Symbols
- object target = Activator.CreateInstance(symbolsType);
+ object? target = Activator.CreateInstance(symbolsType);
// Create an instance delegate for the GetSourceLineInfo method
GetSourceLineInfoDelegate getSourceLineInfo = (GetSourceLineInfoDelegate)symbolsMethodInfo.CreateDelegate(typeof(GetSourceLineInfoDelegate), target);
{
// If there was some reason not to try get the symbols from the portable PDB reader like the module was
// ENC or the source/line info was already retrieved, the method token is 0.
- if (rgiMethodToken[index] != 0)
+ if (rgiMethodToken![index] != 0)
{
- s_getSourceLineInfo(rgAssembly[index], rgAssemblyPath[index], rgLoadedPeAddress[index], rgiLoadedPeSize[index],
- rgInMemoryPdbAddress[index], rgiInMemoryPdbSize[index], rgiMethodToken[index],
- rgiILOffset[index], out rgFilename[index], out rgiLineNumber[index], out rgiColumnNumber[index]);
+ s_getSourceLineInfo!(rgAssembly![index], rgAssemblyPath![index]!, rgLoadedPeAddress![index], rgiLoadedPeSize![index],
+ rgInMemoryPdbAddress![index], rgiInMemoryPdbSize![index], rgiMethodToken![index],
+ rgiILOffset![index], out rgFilename![index], out rgiLineNumber![index], out rgiColumnNumber![index]);
}
}
}
}
}
- public virtual MethodBase GetMethodBase(int i)
+ public virtual MethodBase? GetMethodBase(int i)
{
// There may be a better way to do this.
// we got RuntimeMethodHandles here and we need to go to MethodBase
// but we don't know whether the reflection info has been initialized
// or not. So we call GetMethods and GetConstructors on the type
// and then we fetch the proper MethodBase!!
- IntPtr mh = rgMethodHandle[i];
+ IntPtr mh = rgMethodHandle![i];
if (mh == IntPtr.Zero)
return null;
- IRuntimeMethodInfo mhReal = RuntimeMethodHandle.GetTypicalMethodDefinition(new RuntimeMethodInfoStub(mh, this));
+ IRuntimeMethodInfo? mhReal = RuntimeMethodHandle.GetTypicalMethodDefinition(new RuntimeMethodInfoStub(mh, this));
return RuntimeType.GetMethodBase(mhReal);
}
- public virtual int GetOffset(int i) { return rgiOffset[i]; }
- public virtual int GetILOffset(int i) { return rgiILOffset[i]; }
- public virtual string GetFilename(int i) { return rgFilename == null ? null : rgFilename[i]; }
+ public virtual int GetOffset(int i) { return rgiOffset![i]; }
+ public virtual int GetILOffset(int i) { return rgiILOffset![i]; }
+ public virtual string? GetFilename(int i) { return rgFilename == null ? null : rgFilename[i]; }
public virtual int GetLineNumber(int i) { return rgiLineNumber == null ? 0 : rgiLineNumber[i]; }
public virtual int GetColumnNumber(int i) { return rgiColumnNumber == null ? 0 : rgiColumnNumber[i]; }
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Threading;
using System.Runtime.CompilerServices;
using System.Reflection;
public partial class StackTrace
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern void GetStackFramesInternal(StackFrameHelper sfh, int iSkip, bool fNeedFileInfo, Exception e);
+ internal static extern void GetStackFramesInternal(StackFrameHelper sfh, int iSkip, bool fNeedFileInfo, Exception? e);
internal static int CalculateFramesToSkip(StackFrameHelper StackF, int iNumFrames)
{
// System.Diagnostics functions
for (int i = 0; i < iNumFrames; i++)
{
- MethodBase mb = StackF.GetMethodBase(i);
+ MethodBase? mb = StackF.GetMethodBase(i);
if (mb != null)
{
- Type t = mb.DeclaringType;
+ Type? t = mb.DeclaringType;
if (t == null)
break;
- string ns = t.Namespace;
+ string? ns = t.Namespace;
if (ns == null)
break;
if (!string.Equals(ns, PackageName, StringComparison.Ordinal))
return iRetVal;
}
- private void InitializeForException(Exception exception, int skipFrames, bool fNeedFileInfo)
+ private void InitializeForException(Exception? exception, int skipFrames, bool fNeedFileInfo)
{
CaptureStackTrace(skipFrames, fNeedFileInfo, exception);
}
/// Retrieves an object with stack trace information encoded.
/// It leaves out the first "iSkip" lines of the stacktrace.
/// </summary>
- private void CaptureStackTrace(int skipFrames, bool fNeedFileInfo, Exception e)
+ private void CaptureStackTrace(int skipFrames, bool fNeedFileInfo, Exception? e)
{
_methodsToSkip = skipFrames;
StackTrace st = new StackTrace(this, fNeedFileInfo: false);
if (st.FrameCount > 0)
{
- StackFrame sf = st.GetFrame(0);
- MethodBase method = sf.GetMethod();
+ StackFrame sf = st.GetFrame(0)!;
+ MethodBase method = sf.GetMethod()!;
Module module = method.Module;
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Diagnostics
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
// Do not remove this, it is needed to retain calls to these conditional methods in release builds
#define DEBUG
using System.Threading;
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Print(string message)
+ public static void Print(string? message)
{
Write(message);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Print(string format, params object[] args)
+ public static void Print(string format, params object?[] args)
{
Write(string.Format(null, format, args));
}
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Assert(bool condition, string message)
+ public static void Assert(bool condition, string? message)
{
Assert(condition, message, string.Empty);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Assert(bool condition, string message, string detailMessage)
+ public static void Assert(bool condition, string? message, string? detailMessage)
{
if (!condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Fail(string message)
+ public static void Fail(string? message)
{
Fail(message, string.Empty);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Fail(string message, string detailMessage)
+ public static void Fail(string? message, string? detailMessage)
{
s_provider.Fail(message, detailMessage);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Assert(bool condition, string message, string detailMessageFormat, params object[] args)
+ public static void Assert(bool condition, string? message, string detailMessageFormat, params object?[] args)
{
Assert(condition, message, string.Format(detailMessageFormat, args));
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(string message)
+ public static void WriteLine(string? message)
{
s_provider.WriteLine(message);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Write(string message)
+ public static void Write(string? message)
{
s_provider.Write(message);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(object value)
+ public static void WriteLine(object? value)
{
WriteLine(value?.ToString());
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(object value, string category)
+ public static void WriteLine(object? value, string? category)
{
WriteLine(value?.ToString(), category);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(string format, params object[] args)
+ public static void WriteLine(string format, params object?[] args)
{
WriteLine(string.Format(null, format, args));
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(string message, string category)
+ public static void WriteLine(string? message, string? category)
{
if (category == null)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Write(object value)
+ public static void Write(object? value)
{
Write(value?.ToString());
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Write(string message, string category)
+ public static void Write(string? message, string? category)
{
if (category == null)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void Write(object value, string category)
+ public static void Write(object? value, string? category)
{
Write(value?.ToString(), category);
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, string message)
+ public static void WriteIf(bool condition, string? message)
{
if (condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, object value)
+ public static void WriteIf(bool condition, object? value)
{
if (condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, string message, string category)
+ public static void WriteIf(bool condition, string? message, string? category)
{
if (condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, object value, string category)
+ public static void WriteIf(bool condition, object? value, string? category)
{
if (condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, object value)
+ public static void WriteLineIf(bool condition, object? value)
{
if (condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, object value, string category)
+ public static void WriteLineIf(bool condition, object? value, string? category)
{
if (condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, string message)
+ public static void WriteLineIf(bool condition, string? message)
{
if (condition)
{
}
[System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, string message, string category)
+ public static void WriteLineIf(bool condition, string? message, string? category)
{
if (condition)
{
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using Microsoft.Win32.SafeHandles;
namespace System.Diagnostics
{
private static readonly bool s_shouldWriteToStdErr = Environment.GetEnvironmentVariable("COMPlus_DebugWriteToStdErr") == "1";
- public static void FailCore(string stackTrace, string message, string detailMessage, string errorSource)
+ public static void FailCore(string stackTrace, string? message, string? detailMessage, string errorSource)
{
if (s_FailCore != null)
{
// We don't want to write UTF-16 to a file like standard error. Ideally we would transcode this
// to UTF8, but the downside of that is it pulls in a bunch of stuff into what is ideally
// a path with minimal dependencies (as to prevent re-entrency), so we'll take the strategy
- // of just throwing away any non ASCII characters from the message and writing the rest
+ // of just throwing away any non ASCII characters from the message and writing the rest
const int BufferLength = 256;
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
public partial class DebugProvider
{
- public static void FailCore(string stackTrace, string message, string detailMessage, string errorSource)
+ public static void FailCore(string stackTrace, string? message, string? detailMessage, string errorSource)
{
if (s_FailCore != null)
{
// We don't want output from multiple threads to be interleaved.
lock (s_ForLock)
{
- if (message == null || message.Length <= WriteChunkLength)
+ if (message.Length <= WriteChunkLength)
{
WriteToDebugger(message);
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
// Do not remove this, it is needed to retain calls to these conditional methods in release builds
#define DEBUG
/// </summary>
public partial class DebugProvider
{
- public virtual void Fail(string message, string detailMessage)
+ public virtual void Fail(string? message, string? detailMessage)
{
string stackTrace;
try
FailCore(stackTrace, message, detailMessage, "Assertion Failed");
}
- internal void WriteAssert(string stackTrace, string message, string detailMessage)
+ internal void WriteAssert(string stackTrace, string? message, string? detailMessage)
{
WriteLine(SR.DebugAssertBanner + Environment.NewLine
+ SR.DebugAssertShortMessage + Environment.NewLine
+ stackTrace);
}
- public virtual void Write(string message)
+ public virtual void Write(string? message)
{
lock (s_lock)
{
}
}
- public virtual void WriteLine(string message)
+ public virtual void WriteLine(string? message)
{
Write(message + Environment.NewLine);
}
private sealed class DebugAssertException : Exception
{
- internal DebugAssertException(string stackTrace) :
+ internal DebugAssertException(string? stackTrace) :
base(Environment.NewLine + stackTrace)
{
}
- internal DebugAssertException(string message, string stackTrace) :
+ internal DebugAssertException(string? message, string? stackTrace) :
base(message + Environment.NewLine + Environment.NewLine + stackTrace)
{
}
- internal DebugAssertException(string message, string detailMessage, string stackTrace) :
+ internal DebugAssertException(string? message, string? detailMessage, string? stackTrace) :
base(message + Environment.NewLine + detailMessage + Environment.NewLine + Environment.NewLine + stackTrace)
{
}
private bool _needIndent = true;
- private string _indentString;
+ private string? _indentString;
private string GetIndentString()
{
int indentCount = Debug.IndentSize * Debug.IndentLevel;
if (_indentString?.Length == indentCount)
{
- return _indentString;
+ return _indentString!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34942
}
return _indentString = new string(' ', indentCount);
}
// internal and not readonly so that the tests can swap this out.
- internal static Action<string, string, string, string> s_FailCore = null;
- internal static Action<string> s_WriteCore = null;
+ internal static Action<string, string?, string?, string>? s_FailCore = null;
+ internal static Action<string>? s_WriteCore = null;
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
// Attribute class used by the compiler to mark modules.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
// DebuggerBrowsableState states are defined as follows:
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
// This attribute is used to control what is displayed for the given class or field
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class DebuggerDisplayAttribute : Attribute
{
- private Type _target;
+ private Type? _target;
- public DebuggerDisplayAttribute(string value)
+ public DebuggerDisplayAttribute(string? value)
{
Value = value ?? "";
Name = "";
public string Value { get; }
- public string Name { get; set; }
+ public string? Name { get; set; }
- public string Type { get; set; }
+ public string? Type { get; set; }
- public Type Target
+ public Type? Target
{
get => _target;
set
}
}
- public string TargetTypeName { get; set; }
+ public string? TargetTypeName { get; set; }
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)]
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
#if PROJECTN
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
/// <summary>Indicates the code following the attribute is to be executed in run, not step, mode.</summary>
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class DebuggerTypeProxyAttribute : Attribute
{
- private Type _target;
+ private Type? _target;
public DebuggerTypeProxyAttribute(Type type)
{
ProxyTypeName = type.AssemblyQualifiedName;
}
- public DebuggerTypeProxyAttribute(string typeName)
+ public DebuggerTypeProxyAttribute(string? typeName)
{
ProxyTypeName = typeName;
}
- public string ProxyTypeName { get; }
+ public string? ProxyTypeName { get; }
- public Type Target
+ public Type? Target
{
get => _target;
set
}
}
- public string TargetTypeName { get; set; }
+ public string? TargetTypeName { get; set; }
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
/// <summary>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class DebuggerVisualizerAttribute : Attribute
{
- private Type _target;
+ private Type? _target;
- public DebuggerVisualizerAttribute(string visualizerTypeName)
+ public DebuggerVisualizerAttribute(string? visualizerTypeName)
{
VisualizerTypeName = visualizerTypeName;
}
- public DebuggerVisualizerAttribute(string visualizerTypeName, string visualizerObjectSourceTypeName)
+ public DebuggerVisualizerAttribute(string? visualizerTypeName, string? visualizerObjectSourceTypeName)
{
VisualizerTypeName = visualizerTypeName;
VisualizerObjectSourceTypeName = visualizerObjectSourceTypeName;
}
- public DebuggerVisualizerAttribute(string visualizerTypeName, Type visualizerObjectSource)
+ public DebuggerVisualizerAttribute(string? visualizerTypeName, Type visualizerObjectSource)
{
if (visualizerObjectSource == null)
{
VisualizerObjectSourceTypeName = visualizerObjectSource.AssemblyQualifiedName;
}
- public DebuggerVisualizerAttribute(Type visualizer, string visualizerObjectSourceTypeName)
+ public DebuggerVisualizerAttribute(Type visualizer, string? visualizerObjectSourceTypeName)
{
if (visualizer == null)
{
VisualizerObjectSourceTypeName = visualizerObjectSourceTypeName;
}
- public string VisualizerObjectSourceTypeName { get; }
+ public string? VisualizerObjectSourceTypeName { get; }
- public string VisualizerTypeName { get; }
+ public string? VisualizerTypeName { get; }
- public string Description { get; set; }
+ public string? Description { get; set; }
- public Type Target
+ public Type? Target
{
get => _target;
set
}
}
- public string TargetTypeName { get; set; }
+ public string? TargetTypeName { get; set; }
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Text;
using System.Reflection;
/// <summary>
/// Reflection information for the method if available, null otherwise.
/// </summary>
- private MethodBase _method;
+ private MethodBase? _method;
/// <summary>
/// Native offset of the current instruction within the current method if available,
/// <summary>
/// Source file name representing the current code location if available, null otherwise.
/// </summary>
- private string _fileName;
+ private string? _fileName;
/// <summary>
/// Line number representing the current code location if available, 0 otherwise.
/// name and line number. Use when you don't want to use the
/// debugger's line mapping logic.
/// </summary>
- public StackFrame(string fileName, int lineNumber)
+ public StackFrame(string? fileName, int lineNumber)
{
InitMembers();
/// name, line number and column number. Use when you don't want to
/// use the debugger's line mapping logic.
/// </summary>
- public StackFrame(string fileName, int lineNumber, int colNumber)
+ public StackFrame(string? fileName, int lineNumber, int colNumber)
: this (fileName, lineNumber)
{
_columnNumber = colNumber;
/// <summary>
/// Returns the method the frame is executing
/// </summary>
- public virtual MethodBase GetMethod()
+ public virtual MethodBase? GetMethod()
{
return _method;
}
/// information is normally extracted from the debugging symbols
/// for the executable.
/// </summary>
- public virtual string GetFileName()
+ public virtual string? GetFileName()
{
return _fileName;
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
/// <summary>
/// Stack frames comprising this stack trace.
/// </summary>
- private StackFrame[] _stackFrames;
+ private StackFrame?[]? _stackFrames;
/// <summary>
/// Constructs a stack trace from the current location.
/// Returns a given stack frame. Stack frames are numbered starting at
/// zero, which is the last stack frame pushed.
/// </summary>
- public virtual StackFrame GetFrame(int index)
+ public virtual StackFrame? GetFrame(int index)
{
if (_stackFrames != null && index < _numOfFrames && index >= 0)
return _stackFrames[index + _methodsToSkip];
/// The nth element of this array is the same as GetFrame(n).
/// The length of the array is the same as FrameCount.
/// </summary>
- public virtual StackFrame[] GetFrames()
+ public virtual StackFrame?[]? GetFrames()
{
if (_stackFrames == null || _numOfFrames <= 0)
return null;
StringBuilder sb = new StringBuilder(255);
for (int iFrameIndex = 0; iFrameIndex < _numOfFrames; iFrameIndex++)
{
- StackFrame sf = GetFrame(iFrameIndex);
- MethodBase mb = sf.GetMethod();
+ StackFrame? sf = GetFrame(iFrameIndex);
+ MethodBase? mb = sf?.GetMethod();
if (mb != null && (ShowInStackTrace(mb) ||
(iFrameIndex == _numOfFrames - 1))) // Don't filter last frame
{
sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At);
bool isAsync = false;
- Type declaringType = mb.DeclaringType;
+ Type? declaringType = mb.DeclaringType;
string methodName = mb.Name;
bool methodChanged = false;
if (declaringType != null && declaringType.IsDefined(typeof(CompilerGeneratedAttribute), inherit: false))
isAsync = typeof(IAsyncStateMachine).IsAssignableFrom(declaringType);
if (isAsync || typeof(IEnumerator).IsAssignableFrom(declaringType))
{
- methodChanged = TryResolveStateMachineMethod(ref mb, out declaringType);
+ methodChanged = TryResolveStateMachineMethod(ref mb!, out declaringType); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
}
}
sb.Append(']');
}
- ParameterInfo[] pi = null;
+ ParameterInfo[]? pi = null;
try
{
pi = mb.GetParameters();
}
// source location printing
- if (sf.GetILOffset() != -1)
+ if (sf!.GetILOffset() != -1)
{
// If we don't have a PDB or PDB-reading is disabled for the module,
// then the file name will be null.
- string fileName = sf.GetFileName();
+ string? fileName = sf.GetFileName();
if (fileName != null)
{
declaringType = method.DeclaringType;
- Type parentType = declaringType.DeclaringType;
+ Type? parentType = declaringType.DeclaringType;
if (parentType == null)
{
return false;
}
- MethodInfo[] methods = parentType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
+ MethodInfo[]? methods = parentType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
if (methods == null)
{
return false;
foreach (MethodInfo candidateMethod in methods)
{
- IEnumerable<StateMachineAttribute> attributes = candidateMethod.GetCustomAttributes<StateMachineAttribute>(inherit: false);
+ IEnumerable<StateMachineAttribute>? attributes = candidateMethod.GetCustomAttributes<StateMachineAttribute>(inherit: false);
if (attributes == null)
{
continue;
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
+
namespace System.Diagnostics
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]