/// <summary> /// Creates a SARIF StackFrame instance from a .NET StackFrame instance /// </summary> /// <param name="stackTrace"></param> /// <returns></returns> public static StackFrame Create(System.Diagnostics.StackFrame dotNetStackFrame) { // This value is -1 if not present int ilOffset = dotNetStackFrame.GetILOffset(); string fileName = dotNetStackFrame.GetFileName(); int nativeOffset = dotNetStackFrame.GetNativeOffset(); MethodBase methodBase = dotNetStackFrame.GetMethod(); Assembly assembly = methodBase?.DeclaringType.Assembly; string fullyQualifiedName = CreateFullyQualifiedName(methodBase); StackFrame stackFrame = new StackFrame { Module = assembly?.GetName().Name, FullyQualifiedLogicalName = fullyQualifiedName }; if (fileName != null) { stackFrame.Uri = new Uri(fileName); stackFrame.Line = dotNetStackFrame.GetFileLineNumber(); stackFrame.Column = dotNetStackFrame.GetFileColumnNumber(); } if (ilOffset != -1) { stackFrame.Offset = ilOffset; } if (nativeOffset != -1) { stackFrame.SetProperty("NativeOffset", nativeOffset.ToString(CultureInfo.InvariantCulture)); } return stackFrame; }
public bool ValueEquals(StackFrame other) => ValueComparer.Equals(this, other);
/// <summary> /// Initializes a new instance of the <see cref="StackFrame" /> class from the specified instance. /// </summary> /// <param name="other"> /// The instance from which the new instance is to be initialized. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="other" /> is null. /// </exception> public StackFrame(StackFrame other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Init(other.Message, other.Uri, other.UriBaseId, other.Line, other.Column, other.Module, other.ThreadId, other.FullyQualifiedLogicalName, other.LogicalLocationKey, other.Address, other.Offset, other.Parameters, other.Properties); }
/// <summary> /// Creates a SARIF StackFrame instance from a .NET StackFrame instance /// </summary> /// <param name="dotNetStackFrame"></param> /// <returns></returns> public static StackFrame Create(System.Diagnostics.StackFrame dotNetStackFrame) { // This value is -1 if not present int ilOffset = dotNetStackFrame.GetILOffset(); string fileName = dotNetStackFrame.GetFileName(); int nativeOffset = dotNetStackFrame.GetNativeOffset(); MethodBase methodBase = dotNetStackFrame.GetMethod(); Assembly assembly = methodBase?.DeclaringType.Assembly; string fullyQualifiedName = CreateFullyQualifiedName(methodBase); StackFrame stackFrame = new StackFrame { Module = assembly?.GetName().Name, Location = new Location() }; if (!string.IsNullOrWhiteSpace(fullyQualifiedName)) { stackFrame.Location = new Location { LogicalLocation = new LogicalLocation { FullyQualifiedName = fullyQualifiedName } }; } if (fileName != null) { if (stackFrame.Location == null) { stackFrame.Location = new Location(); } stackFrame.Location.PhysicalLocation = new PhysicalLocation { ArtifactLocation = new ArtifactLocation { Uri = new Uri(fileName) }, Region = new Region { StartLine = dotNetStackFrame.GetFileLineNumber(), StartColumn = dotNetStackFrame.GetFileColumnNumber() } }; } if (ilOffset != -1) { if (stackFrame.Location == null) { stackFrame.Location = new Location(); } if (stackFrame.Location.PhysicalLocation == null) { stackFrame.Location.PhysicalLocation = new PhysicalLocation(); } stackFrame.Location.PhysicalLocation.Address = new Address { OffsetFromParent = ilOffset }; } if (nativeOffset != -1) { stackFrame.SetProperty("NativeOffset", nativeOffset.ToString(CultureInfo.InvariantCulture)); } return(stackFrame); }