//#define DEBUG_NETEVENTSOURCE_MISUSE
#endif
+#nullable enable
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.Tracing;
/// <param name="formattableString">A description of the entrance, including any arguments to the call.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Enter(object thisOrContextObject, FormattableString formattableString = null, [CallerMemberName] string memberName = null)
+ public static void Enter(object thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
/// <param name="arg0">The object to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Enter(object thisOrContextObject, object arg0, [CallerMemberName] string memberName = null)
+ public static void Enter(object thisOrContextObject, object arg0, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
/// <param name="arg1">The second object to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Enter(object thisOrContextObject, object arg0, object arg1, [CallerMemberName] string memberName = null)
+ public static void Enter(object thisOrContextObject, object arg0, object arg1, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
/// <param name="arg2">The third object to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Enter(object thisOrContextObject, object arg0, object arg1, object arg2, [CallerMemberName] string memberName = null)
+ public static void Enter(object thisOrContextObject, object arg0, object arg1, object arg2, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
}
[Event(EnterEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)]
- private void Enter(string thisOrContextObject, string memberName, string parameters) =>
+ private void Enter(string thisOrContextObject, string? memberName, string parameters) =>
WriteEvent(EnterEventId, thisOrContextObject, memberName ?? MissingMember, parameters);
#endregion
/// <param name="formattableString">A description of the exit operation, including any return values.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Exit(object thisOrContextObject, FormattableString formattableString = null, [CallerMemberName] string memberName = null)
+ public static void Exit(object thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
/// <param name="arg0">A return value from the member.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Exit(object thisOrContextObject, object arg0, [CallerMemberName] string memberName = null)
+ public static void Exit(object thisOrContextObject, object arg0, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
/// <param name="arg1">A second return value from the member.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Exit(object thisOrContextObject, object arg0, object arg1, [CallerMemberName] string memberName = null)
+ public static void Exit(object thisOrContextObject, object arg0, object arg1, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
}
[Event(ExitEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)]
- private void Exit(string thisOrContextObject, string memberName, string result) =>
+ private void Exit(string thisOrContextObject, string? memberName, string? result) =>
WriteEvent(ExitEventId, thisOrContextObject, memberName ?? MissingMember, result);
#endregion
/// <param name="formattableString">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Info(object thisOrContextObject, FormattableString formattableString = null, [CallerMemberName] string memberName = null)
+ public static void Info(object thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Info(object thisOrContextObject, object message, [CallerMemberName] string memberName = null)
+ public static void Info(object thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(message);
}
[Event(InfoEventId, Level = EventLevel.Informational, Keywords = Keywords.Default)]
- private void Info(string thisOrContextObject, string memberName, string message) =>
+ private void Info(string thisOrContextObject, string? memberName, string? message) =>
WriteEvent(InfoEventId, thisOrContextObject, memberName ?? MissingMember, message);
#endregion
/// <param name="formattableString">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName = null)
+ public static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Error(object thisOrContextObject, object message, [CallerMemberName] string memberName = null)
+ public static void Error(object thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(message);
}
[Event(ErrorEventId, Level = EventLevel.Warning, Keywords = Keywords.Default)]
- private void ErrorMessage(string thisOrContextObject, string memberName, string message) =>
+ private void ErrorMessage(string thisOrContextObject, string? memberName, string? message) =>
WriteEvent(ErrorEventId, thisOrContextObject, memberName ?? MissingMember, message);
#endregion
/// <param name="formattableString">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Fail(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName = null)
+ public static void Fail(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string? memberName = null)
{
// Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations
// that should never happen in production, and thus we don't care about extra costs.
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Fail(object thisOrContextObject, object message, [CallerMemberName] string memberName = null)
+ public static void Fail(object thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
{
// Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations
// that should never happen in production, and thus we don't care about extra costs.
}
[Event(CriticalFailureEventId, Level = EventLevel.Critical, Keywords = Keywords.Debug)]
- private void CriticalFailure(string thisOrContextObject, string memberName, string message) =>
+ private void CriticalFailure(string thisOrContextObject, string? memberName, string? message) =>
WriteEvent(CriticalFailureEventId, thisOrContextObject, memberName ?? MissingMember, message);
#endregion
/// <param name="buffer">The buffer to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void DumpBuffer(object thisOrContextObject, byte[] buffer, [CallerMemberName] string memberName = null)
+ public static void DumpBuffer(object thisOrContextObject, byte[] buffer, [CallerMemberName] string? memberName = null)
{
DumpBuffer(thisOrContextObject, buffer, 0, buffer.Length, memberName);
}
/// <param name="count">The number of bytes to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void DumpBuffer(object thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string memberName = null)
+ public static void DumpBuffer(object thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string? memberName = null)
{
if (IsEnabled)
{
/// <param name="count">The number of bytes to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static unsafe void DumpBuffer(object thisOrContextObject, IntPtr bufferPtr, int count, [CallerMemberName] string memberName = null)
+ public static unsafe void DumpBuffer(object thisOrContextObject, IntPtr bufferPtr, int count, [CallerMemberName] string? memberName = null)
{
Debug.Assert(bufferPtr != IntPtr.Zero);
Debug.Assert(count >= 0);
}
[Event(DumpArrayEventId, Level = EventLevel.Verbose, Keywords = Keywords.Debug)]
- private unsafe void DumpBuffer(string thisOrContextObject, string memberName, byte[] buffer) =>
+ private unsafe void DumpBuffer(string thisOrContextObject, string? memberName, byte[] buffer) =>
WriteEvent(DumpArrayEventId, thisOrContextObject, memberName ?? MissingMember, buffer);
#endregion
/// <param name="second">The second object.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Associate(object first, object second, [CallerMemberName] string memberName = null)
+ public static void Associate(object first, object second, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(first);
DebugValidateArg(second);
/// <param name="second">The second object.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
- public static void Associate(object thisOrContextObject, object first, object second, [CallerMemberName] string memberName = null)
+ public static void Associate(object thisOrContextObject, object first, object second, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(first);
}
[Event(AssociateEventId, Level = EventLevel.Informational, Keywords = Keywords.Default, Message = "[{2}]<-->[{3}]")]
- private void Associate(string thisOrContextObject, string memberName, string first, string second) =>
+ private void Associate(string thisOrContextObject, string? memberName, string first, string second) =>
WriteEvent(AssociateEventId, thisOrContextObject, memberName ?? MissingMember, first, second);
#endregion
#endregion
}
[Conditional("DEBUG_NETEVENTSOURCE_MISUSE")]
- private static void DebugValidateArg(FormattableString arg)
+ private static void DebugValidateArg(FormattableString? arg)
{
Debug.Assert(IsEnabled || arg == null, $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled");
}
public static int GetHashCode(object value) => value?.GetHashCode() ?? 0;
[NonEvent]
- public static object Format(object value)
+ public static object Format(object? value)
{
// If it's null, return a known string for null values
if (value == null)
}
// Give another partial implementation a chance to provide its own string representation
- string result = null;
+ string? result = null;
AdditionalCustomizedToString(value, ref result);
if (result != null)
{
}
// Format arrays with their element type name and length
- Array arr = value as Array;
- if (arr != null)
+ if (value is Array arr)
{
return $"{arr.GetType().GetElementType()}[{((Array)value).Length}]";
}
// Format ICollections as the name and count
- ICollection c = value as ICollection;
- if (c != null)
+ if (value is ICollection c)
{
return $"{c.GetType().Name}({c.Count})";
}
// Format SafeHandles as their type, hash code, and pointer value
- SafeHandle handle = value as SafeHandle;
- if (handle != null)
+ if (value is SafeHandle handle)
{
return $"{handle.GetType().Name}:{handle.GetHashCode()}(0x{handle.DangerousGetHandle():X})";
}
// If the string representation of the instance would just be its type name,
// use its id instead.
- string toString = value.ToString();
+ string? toString = value.ToString();
if (toString == null || toString == value.GetType().FullName)
{
return IdOf(value);
case 2: return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)));
case 3: return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)), Format(s.GetArgument(2)));
default:
- object[] args = s.GetArguments();
+ object?[] args = s.GetArguments();
object[] formattedArgs = new object[args.Length];
for (int i = 0; i < args.Length; i++)
{
}
}
- static partial void AdditionalCustomizedToString<T>(T value, ref string result);
+ static partial void AdditionalCustomizedToString<T>(T value, ref string? result);
#endregion
#region Custom WriteEvent overloads
protected WebHeaderCollection(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { }
public override string[] AllKeys { get { throw null; } }
public override int Count { get { throw null; } }
- public string this[System.Net.HttpRequestHeader header] { get { throw null; } set { } }
- public string this[System.Net.HttpResponseHeader header] { get { throw null; } set { } }
- public new string this[string name] { get { throw null; } set { } }
+ public string? this[System.Net.HttpRequestHeader header] { get { throw null; } set { } }
+ public string? this[System.Net.HttpResponseHeader header] { get { throw null; } set { } }
+ public new string? this[string name] { get { throw null; } set { } }
public override System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys { get { throw null; } }
- public void Add(System.Net.HttpRequestHeader header, string value) { }
- public void Add(System.Net.HttpResponseHeader header, string value) { }
+ public void Add(System.Net.HttpRequestHeader header, string? value) { }
+ public void Add(System.Net.HttpResponseHeader header, string? value) { }
public void Add(string header) { }
- public override void Add(string name, string value) { }
- protected void AddWithoutValidate(string headerName, string headerValue) { }
+ public override void Add(string name, string? value) { }
+ protected void AddWithoutValidate(string headerName, string? headerValue) { }
public override void Clear() { }
- public override string Get(int index) { throw null; }
- public override string Get(string name) { throw null; }
+ public override string? Get(int index) { throw null; }
+ public override string? Get(string? name) { throw null; }
public override System.Collections.IEnumerator GetEnumerator() { throw null; }
public override string GetKey(int index) { throw null; }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { }
- public override string[] GetValues(int index) { throw null; }
- public override string[] GetValues(string header) { throw null; }
+ public override string[]? GetValues(int index) { throw null; }
+ public override string[]? GetValues(string header) { throw null; }
public static bool IsRestricted(string headerName) { throw null; }
public static bool IsRestricted(string headerName, bool response) { throw null; }
- public override void OnDeserialization(object sender) { }
+ public override void OnDeserialization(object? sender) { }
public void Remove(System.Net.HttpRequestHeader header) { }
public void Remove(System.Net.HttpResponseHeader header) { }
public override void Remove(string name) { }
- public void Set(System.Net.HttpRequestHeader header, string value) { }
- public void Set(System.Net.HttpResponseHeader header, string value) { }
- public override void Set(string name, string value) { }
+ public void Set(System.Net.HttpRequestHeader header, string? value) { }
+ public void Set(System.Net.HttpResponseHeader header, string? value) { }
+ public override void Set(string name, string? value) { }
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { }
public byte[] ToByteArray() { throw null; }
public override string ToString() { throw null; }
using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
+using System.Diagnostics.CodeAnalysis;
namespace System.Net
{
private const int ApproxAveHeaderLineSize = 30;
private const int ApproxHighAvgNumHeaders = 16;
private WebHeaderCollectionType _type;
- private NameValueCollection _innerCollection;
+ private NameValueCollection? _innerCollection;
- private static HeaderInfoTable _headerInfo;
+ private static HeaderInfoTable? _headerInfo;
protected WebHeaderCollection(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
}
}
- public string this[HttpRequestHeader header]
+ public string? this[HttpRequestHeader header]
{
get
{
}
}
- public string this[HttpResponseHeader header]
+ public string? this[HttpResponseHeader header]
{
get
{
}
}
- public override void Set(string name, string value)
+#pragma warning disable CS8610 // Nullability of parameter 'name' doesn't match overridden member
+ public override void Set(string name, string? value)
+#pragma warning restore CS8610
{
if (string.IsNullOrEmpty(name))
{
InnerCollection.Set(name, value);
}
- public void Set(HttpRequestHeader header, string value)
+ public void Set(HttpRequestHeader header, string? value)
{
if (!AllowHttpRequestHeader)
{
this.Set(header.GetName(), value);
}
- public void Set(HttpResponseHeader header, string value)
+ public void Set(HttpResponseHeader header, string? value)
{
if (!AllowHttpResponseHeader)
{
this.Remove(header.GetName());
}
- public override void OnDeserialization(object sender)
+ public override void OnDeserialization(object? sender)
{
// Nop in desktop
}
return response ? HeaderInfo[headerName].IsResponseRestricted : HeaderInfo[headerName].IsRequestRestricted;
}
- public override string[] GetValues(int index)
+ public override string[]? GetValues(int index)
{
return InnerCollection.GetValues(index);
}
// header - Name of the header.
// Return Value:
// string[] - array of parsed string objects
- public override string[] GetValues(string header)
+#pragma warning disable CS8610 // Nullability of parameter 'header' doesn't match overridden member
+ public override string[]? GetValues(string header)
+#pragma warning restore CS8610
{
// First get the information about the header and the values for
// the header.
- HeaderInfo info = HeaderInfo[header];
- string[] values = InnerCollection.GetValues(header);
+ HeaderInfo info = HeaderInfo[header!];
+ string[]? values = InnerCollection.GetValues(header);
// If we have no information about the header or it doesn't allow
// multiple values, just return the values.
if (info == null || values == null || !info.AllowMultiValues)
// We do some optimazation here, where we try not to copy the
// values unless there really is one that have multiple values.
string[] tempValues;
- List<string> valueList = null;
+ List<string>? valueList = null;
for (int i = 0; i < values.Length; i++)
{
// Parse this value header.
public override string GetKey(int index)
{
- return InnerCollection.GetKey(index);
+ return InnerCollection.GetKey(index)!;
}
public override void Clear()
}
}
- public override string Get(int index)
+ public override string? Get(int index)
{
if (_innerCollection == null)
{
return _innerCollection.Get(index);
}
- public override string Get(string name)
+ public override string? Get(string? name)
{
if (_innerCollection == null)
{
return _innerCollection.Get(name);
}
- public void Add(HttpRequestHeader header, string value)
+ public void Add(HttpRequestHeader header, string? value)
{
if (!AllowHttpRequestHeader)
{
this.Add(header.GetName(), value);
}
- public void Add(HttpResponseHeader header, string value)
+ public void Add(HttpResponseHeader header, string? value)
{
if (!AllowHttpResponseHeader)
{
InnerCollection.Add(name, value);
}
- public override void Add(string name, string value)
+#pragma warning disable CS8610 // Nullability of parameter 'name' doesn't match overridden member
+ public override void Add(string name, string? value)
+#pragma warning restore CS8610
{
if (name == null)
{
InnerCollection.Add(name, value);
}
- protected void AddWithoutValidate(string headerName, string headerValue)
+ protected void AddWithoutValidate(string headerName, string? headerValue)
{
headerName = HttpValidationHelpers.CheckBadHeaderNameChars(headerName);
headerValue = HttpValidationHelpers.CheckBadHeaderValueChars(headerValue);
/// <devdoc>
/// <para>Removes the specified header.</para>
/// </devdoc>
+#pragma warning disable CS8610 // Nullability of parameter 'name' doesn't match overridden member
public override void Remove(string name)
+#pragma warning restore CS8610
{
if (string.IsNullOrEmpty(name))
{
var sb = new StringBuilder(ApproxAveHeaderLineSize * Count);
- foreach (string key in InnerCollection)
+ foreach (string? key in InnerCollection)
{
- string val = InnerCollection.Get(key);
+ string? val = InnerCollection.Get(key);
sb.Append(key)
.Append(": ")
.Append(val)
{
get
{
- return InnerCollection.AllKeys;
+ return InnerCollection.AllKeys!;
}
}