Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System;

namespace Microsoft.Extensions.Logging
Expand All @@ -20,12 +22,12 @@ private NullExternalScopeProvider()
public static IExternalScopeProvider Instance { get; } = new NullExternalScopeProvider();

/// <inheritdoc />
void IExternalScopeProvider.ForEachScope<TState>(Action<object, TState> callback, TState state)
void IExternalScopeProvider.ForEachScope<TState>(Action<object?, TState> callback, TState state)
{
}

/// <inheritdoc />
IDisposable IExternalScopeProvider.Push(object state)
IDisposable IExternalScopeProvider.Push(object? state)
{
return NullScope.Instance;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Extensions.Internal
{
Expand Down Expand Up @@ -31,7 +34,8 @@ internal static class TypeNameHelper
{ typeof(ushort), "ushort" }
};

public static string GetTypeDisplayName(object item, bool fullName = true)
[return: NotNullIfNotNull("item")]
public static string? GetTypeDisplayName(object? item, bool fullName = true)
{
return item == null ? null : GetTypeDisplayName(item.GetType(), fullName);
}
Expand Down Expand Up @@ -63,7 +67,7 @@ private static void ProcessType(StringBuilder builder, Type type, in DisplayName
{
ProcessArrayType(builder, type, options);
}
else if (_builtInTypeNames.TryGetValue(type, out string builtInName))
else if (_builtInTypeNames.TryGetValue(type, out string? builtInName))
{
builder.Append(builtInName);
}
Expand All @@ -76,7 +80,7 @@ private static void ProcessType(StringBuilder builder, Type type, in DisplayName
}
else
{
string name = options.FullName ? type.FullName : type.Name;
string name = options.FullName ? type.FullName! : type.Name;
builder.Append(name);

if (options.NestedTypeDelimiter != DefaultNestedTypeDelimiter)
Expand All @@ -91,7 +95,7 @@ private static void ProcessArrayType(StringBuilder builder, Type type, in Displa
Type innerType = type;
while (innerType.IsArray)
{
innerType = innerType.GetElementType();
innerType = innerType.GetElementType()!;
}

ProcessType(builder, innerType, options);
Expand All @@ -101,7 +105,7 @@ private static void ProcessArrayType(StringBuilder builder, Type type, in Displa
builder.Append('[');
builder.Append(',', type.GetArrayRank() - 1);
builder.Append(']');
type = type.GetElementType();
type = type.GetElementType()!;
}
}

Expand All @@ -110,14 +114,14 @@ private static void ProcessGenericType(StringBuilder builder, Type type, Type[]
int offset = 0;
if (type.IsNested)
{
offset = type.DeclaringType.GetGenericArguments().Length;
offset = type.DeclaringType!.GetGenericArguments().Length;
}

if (options.FullName)
{
if (type.IsNested)
{
ProcessGenericType(builder, type.DeclaringType, genericArguments, offset, options);
ProcessGenericType(builder, type.DeclaringType!, genericArguments, offset, options);
builder.Append(options.NestedTypeDelimiter);
}
else if (!string.IsNullOrEmpty(type.Namespace))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>$(NetCoreAppCurrent);net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<!-- Debug IL generation -->
<ILEmitBackendSaveAssemblies>False</ILEmitBackendSaveAssemblies>
<Nullable>Annotations</Nullable>
</PropertyGroup>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<EnableDefaultItems>true</EnableDefaultItems>
<Nullable>Annotations</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading