// For example, if the element type of the Array is derived from T,
// we can't figure out if we can successfully copy the element beforehand.
//
- Type targetType = array.GetType().GetElementType();
+ Type targetType = array.GetType().GetElementType()!;
Type sourceType = typeof(T);
if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType)))
{
// For example, if the element type of the Array is derived from T,
// we can't figure out if we can successfully copy the element beforehand.
//
- Type targetType = array.GetType().GetElementType();
+ Type targetType = array.GetType().GetElementType()!;
Type sourceType = typeof(T);
if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType)))
{
Assembly? probablyNotRewritten = null;
for (int i = 0; i < stack.FrameCount; i++)
{
- Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType.Assembly;
+ Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType!.Assembly;
if (caller != null && caller != thisAssembly)
{
probablyNotRewritten = caller;
{
#if FEATURE_EVENTSOURCE_XPLAT
- private static readonly EventListener persistent_Xplat_Listener = XplatEventLogger.InitializePersistentListener();
+ private static readonly EventListener? persistent_Xplat_Listener = XplatEventLogger.InitializePersistentListener();
#endif //FEATURE_EVENTSOURCE_XPLAT
/// <summary>
if (eventID == 0)
continue;
- byte[] metadata = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(m_eventData[i]);
+ byte[]? metadata = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(m_eventData[i]);
uint metadataLength = (metadata != null) ? (uint)metadata.Length : 0;
string eventName = m_eventData[i].Name;
exception = e;
}
- Debug.Assert((flags & EventManifestOptions.Strict) != 0 && manifest != null); // TODO-NULLABLE: possible bug: if error is thrown before manifest is assigned in non-strict mode, this will NRE
- if ((flags & EventManifestOptions.Strict) != 0 && (manifest.Errors.Count > 0 || exception != null))
+ // TODO-NULLABLE: possible bug: if error is thrown before manifest is assigned in non-strict mode, this will NRE
+ if ((flags & EventManifestOptions.Strict) != 0 && (manifest!.Errors.Count > 0 || exception != null))
{
string msg = string.Empty;
{
if ((eventHandle = eventHandleTable[descriptor.EventId]) == IntPtr.Zero)
{
- byte[] metadataBlob = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(
+ byte[]? metadataBlob = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(
descriptor.EventId,
name,
(EventKeywords)descriptor.Keywords,
public virtual EventInfo? GetDeclaredEvent(string name) => GetEvent(name, TypeInfo.DeclaredOnlyLookup);
public virtual FieldInfo? GetDeclaredField(string name) => GetField(name, TypeInfo.DeclaredOnlyLookup);
public virtual MethodInfo? GetDeclaredMethod(string name) => GetMethod(name, TypeInfo.DeclaredOnlyLookup);
- public virtual TypeInfo? GetDeclaredNestedType(string name) => GetNestedType(name, TypeInfo.DeclaredOnlyLookup)!.GetTypeInfo();
+ public virtual TypeInfo? GetDeclaredNestedType(string name) => GetNestedType(name, TypeInfo.DeclaredOnlyLookup)?.GetTypeInfo();
public virtual PropertyInfo? GetDeclaredProperty(string name) => GetProperty(name, TypeInfo.DeclaredOnlyLookup);
public virtual IEnumerable<MethodInfo> GetDeclaredMethods(string name)
// statics used to dynamically call into BinaryFormatter
// When successfully located s_binaryFormatterType will point to the BinaryFormatter type
// and s_deserializeMethod will point to an unbound delegate to the deserialize method.
- private static Type s_binaryFormatterType;
- private static Func<object?, Stream, object> s_deserializeMethod;
+ private static Type? s_binaryFormatterType;
+ private static Func<object?, Stream, object>? s_deserializeMethod;
// This is the constructor the RuntimeResourceSet calls,
- // passing in the stream to read from and the RuntimeResourceSet's
+ // passing in the stream to read from and the RuntimeResourceSet's
// internal hash table (hash table of names with file offsets
// and values, coupled to this ResourceReader).
internal ResourceReader(Stream stream, Dictionary<string, ResourceLocator> resCache, bool permitDeserialization)
Type type = FindType(typeIndex);
- object graph = s_deserializeMethod(_binaryFormatter, _store.BaseStream);
+ object graph = s_deserializeMethod!(_binaryFormatter, _store.BaseStream);
// guard against corrupted resources
if (graph.GetType() != type)
LazyInitializer.EnsureInitialized(ref s_deserializeMethod, () =>
{
- MethodInfo binaryFormatterDeserialize = s_binaryFormatterType.GetMethod("Deserialize", new Type[] { typeof(Stream) });
+ MethodInfo binaryFormatterDeserialize = s_binaryFormatterType!.GetMethod("Deserialize", new Type[] { typeof(Stream) })!;
// create an unbound delegate that can accept a BinaryFormatter instance as object
return (Func<object?, Stream, object>)typeof(ResourceReader)
- .GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static)
- .MakeGenericMethod(s_binaryFormatterType)
- .Invoke(null, new object[] { binaryFormatterDeserialize });
+ .GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static)!
+ .MakeGenericMethod(s_binaryFormatterType)!
+ .Invoke(null, new object[] { binaryFormatterDeserialize })!;
});
- _binaryFormatter = Activator.CreateInstance(s_binaryFormatterType);
+ _binaryFormatter = Activator.CreateInstance(s_binaryFormatterType!)!;
}
// generic method that we specialize at runtime once we've loaded the BinaryFormatter type
}
resourceType = TypeNameFromTypeCode(typeCode);
- // The length must be adjusted to subtract off the number
+ // The length must be adjusted to subtract off the number
// of bytes in the 7 bit encoded type code.
len -= (int)(_store.BaseStream.Position - (_dataSectionOffset + dataPos));
byte[] bytes = _store.ReadBytes(len);
}
}
- public object Value
+ public object? Value
{
get
{
return key is TKey;
}
- void IDictionary.Add(object key, object value)
+ void IDictionary.Add(object key, object? value)
{
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}
// For example, if the element type of the Array is derived from T,
// we can't figure out if we can successfully copy the element beforehand.
//
- Type targetType = array.GetType().GetElementType();
+ Type targetType = array.GetType().GetElementType()!;
Type sourceType = typeof(T);
if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType)))
{
EventParameterInfo[] eventParams = new EventParameterInfo[parameters.Length];
for(int i = 0; i < parameters.Length; i++)
{
- eventParams[i].SetInfo(parameters[i].Name, parameters[i].ParameterType);
+ eventParams[i].SetInfo(parameters[i].Name!, parameters[i].ParameterType);
}
return GenerateMetadata(
internal unsafe void ProcessEvent(uint eventID, uint osThreadID, DateTime timeStamp, Guid activityId, Guid childActivityId, ReadOnlySpan<Byte> payload)
{
// Make sure the eventID is valid.
- if (eventID >= m_eventData.Length)
+ if (eventID >= m_eventData!.Length)
{
return;
}
private static extern bool IsEventSourceLoggingEnabled();
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void LogEventSource(int eventID, string eventName, string eventSourceName, string payload);
+ private static extern void LogEventSource(int eventID, string? eventName, string eventSourceName, string payload);
static List<char> escape_seq = new List<char> { '\b', '\f', '\n', '\r', '\t', '\"', '\\' };
static Dictionary<char, string> seq_mapping = new Dictionary<char, string>()
}
}
- private static string Serialize(ReadOnlyCollection<string>? payloadName, ReadOnlyCollection<object> payload, string? eventMessage)
+ private static string Serialize(ReadOnlyCollection<string>? payloadName, ReadOnlyCollection<object?>? payload, string? eventMessage)
{
if (payloadName == null || payload == null)
return string.Empty;
{
if(payload[i] != null)
{
- sb.Append(payload[i].ToString());
+ sb.Append(payload[i]!.ToString()); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
}
break;
}
internal protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
string? eventFilter = eventSourceEventFilter.Value;
- if (string.IsNullOrEmpty(eventFilter) || (eventData.EventName.IndexOf(eventFilter, StringComparison.OrdinalIgnoreCase) >= 0))
+ if (string.IsNullOrEmpty(eventFilter) || (eventData.EventName!.IndexOf(eventFilter, StringComparison.OrdinalIgnoreCase) >= 0))
{
LogOnEventWritten(eventData);
}
private static extern bool nIsTransientInternal(RuntimeModule module);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetScopeName(RuntimeModule module, StringHandleOnStack? retString);
+ private static extern void GetScopeName(RuntimeModule module, StringHandleOnStack retString);
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern void GetFullyQualifiedName(RuntimeModule module, StringHandleOnStack? retString);
+ private static extern void GetFullyQualifiedName(RuntimeModule module, StringHandleOnStack retString);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern RuntimeType[] GetTypes(RuntimeModule module);
#endif // FEATURE_TYPEEQUIVALENCE
}
- // This type is used to remove the expense of having a managed reference object that is dynamically
+ // This type is used to remove the expense of having a managed reference object that is dynamically
// created when we can prove that we don't need that object. Use of this type requires code to ensure
- // that the underlying native resource is not freed.
+ // that the underlying native resource is not freed.
// Cases in which this may be used:
// 1. When native code calls managed code passing one of these as a parameter
// 2. When managed code acquires one of these from an IRuntimeMethodInfo, and ensure that the IRuntimeMethodInfo is preserved
// across the lifetime of the RuntimeMethodHandleInternal instance
// 3. When another object is used to keep the RuntimeMethodHandleInternal alive. See delegates, CreateInstance cache, Signature structure
- // When in doubt, do not use.
+ // When in doubt, do not use.
internal struct RuntimeMethodHandleInternal
{
internal static RuntimeMethodHandleInternal EmptyHandle
internal static extern LoaderAllocator GetLoaderAllocator(RuntimeMethodHandleInternal method);
}
- // This type is used to remove the expense of having a managed reference object that is dynamically
+ // This type is used to remove the expense of having a managed reference object that is dynamically
// created when we can prove that we don't need that object. Use of this type requires code to ensure
- // that the underlying native resource is not freed.
+ // that the underlying native resource is not freed.
// Cases in which this may be used:
// 1. When native code calls managed code passing one of these as a parameter
// 2. When managed code acquires one of these from an RtFieldInfo, and ensure that the RtFieldInfo is preserved
// across the lifetime of the RuntimeFieldHandleInternal instance
// 3. When another object is used to keep the RuntimeFieldHandleInternal alive.
- // When in doubt, do not use.
+ // When in doubt, do not use.
internal struct RuntimeFieldHandleInternal
{
internal bool IsNullHandle()
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern void GetSignature(
void* pCorSig, int cCorSig,
- RuntimeFieldHandleInternal? fieldHandle, IRuntimeMethodInfo? methodHandle, RuntimeType? declaringType);
+ RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo? methodHandle, RuntimeType? declaringType);
#endregion
internal abstract string GetStringLiteral(int token);
internal abstract void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle);
internal abstract byte[] ResolveSignature(int token, int fromMethod);
- //
+ //
internal abstract MethodInfo GetDynamicMethod();
}
}