return InternalGetCustomAttributes((EventInfo)element, type, inherit);
default:
- return (Attribute[])element.GetCustomAttributes(type, inherit);
+ return (element.GetCustomAttributes(type, inherit) as Attribute[])!;
}
}
return InternalGetCustomAttributes((EventInfo)element, typeof(Attribute), inherit);
default:
- return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
+ return (element.GetCustomAttributes(typeof(Attribute), inherit) as Attribute[])!;
}
}
MemberInfo member = element.Member;
if (member.MemberType == MemberTypes.Method && inherit)
- return InternalParamGetCustomAttributes(element, attributeType, inherit);
+ return InternalParamGetCustomAttributes(element, attributeType, inherit) as Attribute[];
- return (Attribute[])element.GetCustomAttributes(attributeType, inherit);
+ return (element.GetCustomAttributes(attributeType, inherit) as Attribute[])!;
}
public static Attribute[] GetCustomAttributes(ParameterInfo element, bool inherit)
MemberInfo member = element.Member;
if (member.MemberType == MemberTypes.Method && inherit)
- return InternalParamGetCustomAttributes(element, null, inherit);
+ return InternalParamGetCustomAttributes(element, null, inherit) as Attribute[];
- return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
+ return (element.GetCustomAttributes(typeof(Attribute), inherit) as Attribute[])!;
}
public static bool IsDefined(ParameterInfo element, Type attributeType)
else
{
FieldInfo field = attributeType.GetField(name)!;
- field.SetValue(attribute, value!, BindingFlags.Default, Type.DefaultBinder, null);
+ field.SetValue(attribute, value, BindingFlags.Default, Type.DefaultBinder, null);
}
}
catch (Exception e)
isVarArg = false;
// Resolve attribute type from ctor parent token found in decorated decoratedModule scope
- attributeType = (RuntimeType)decoratedModule.ResolveType(scope.GetParentToken(caCtorToken), null, null);
+ attributeType = (decoratedModule.ResolveType(scope.GetParentToken(caCtorToken), null, null) as RuntimeType)!;
// Test attribute type against user provided attribute type filter
if (!(attributeFilterType.IsAssignableFrom(attributeType)))
{
if (signature[i] == null)
throw new ArgumentException(SR.Arg_InvalidTypeInSignature);
-
- if (signature[i].UnderlyingSystemType is RuntimeType rt)
- m_parameterTypes[i] = rt;
- else
- throw new ArgumentException(SR.Arg_InvalidTypeInSignature);
-
- if (m_parameterTypes[i] == typeof(void))
+ m_parameterTypes[i] = (signature[i].UnderlyingSystemType as RuntimeType)!;
+ if (m_parameterTypes[i] == null || m_parameterTypes[i] == typeof(void))
throw new ArgumentException(SR.Arg_InvalidTypeInSignature);
}
}
object retValue;
if (actualCount > 0)
{
- object[] arguments = CheckArguments(parameters!, binder!, invokeAttr, culture, sig);
+ object[] arguments = CheckArguments(parameters!, binder, invokeAttr, culture, sig);
retValue = RuntimeMethodHandle.InvokeMethod(null, arguments, sig, false, wrapExceptions);
// copy out. This should be made only if ByRef are present.
for (int index = 0; index < arguments.Length; index++)
{
var sbName = new ValueStringBuilder(MethodNameBufferSize);
- sbName.Append(ReturnType!.FormatTypeName());
+ sbName.Append(ReturnType.FormatTypeName());
sbName.Append(' ');
sbName.Append(Name);
// _TypeBuilder contains both TypeBuilder and EnumBuilder objects
private Dictionary<string, Type> _typeBuilderDict = null!;
- private ISymbolWriter? _iSymWriter = null;
+ private ISymbolWriter? _iSymWriter;
internal ModuleBuilderData _moduleData = null!;
internal InternalModuleBuilder _internalModuleBuilder;
// This is the "external" AssemblyBuilder
if (masmi != null)
tkParent = GetMethodToken(masmi).Token;
else
- tkParent = GetConstructorToken((ConstructorInfo)method).Token;
+ tkParent = GetConstructorToken((method as ConstructorInfo)!).Token;
}
return GetMemberRefFromSignature(tkParent, method.Name, sigBytes, sigLength);
}
else
{
- tk = GetConstructorToken((ConstructorInfo)method).Token;
+ tk = GetConstructorToken((method as ConstructorInfo)!).Token;
}
}
else
if (!(type is TypeBuilderInstantiation))
throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(type));
- return MethodOnTypeBuilderInstantiation.GetMethod(method, (TypeBuilderInstantiation)type);
+ return MethodOnTypeBuilderInstantiation.GetMethod(method, (type as TypeBuilderInstantiation)!);
}
public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor)
{
if (type.GetGenericTypeDefinition() != constructor.DeclaringType)
throw new ArgumentException(SR.Argument_InvalidConstructorDeclaringType, nameof(type));
- return ConstructorOnTypeBuilderInstantiation.GetConstructor(constructor, (TypeBuilderInstantiation)type);
+ return ConstructorOnTypeBuilderInstantiation.GetConstructor(constructor, (type as TypeBuilderInstantiation)!);
}
public static FieldInfo GetField(Type type, FieldInfo field)
{
if (type.GetGenericTypeDefinition() != field.DeclaringType)
throw new ArgumentException(SR.Argument_InvalidFieldDeclaringType, nameof(type));
- return FieldOnTypeBuilderInstantiation.GetField(field, (TypeBuilderInstantiation)type);
+ return FieldOnTypeBuilderInstantiation.GetField(field, (type as TypeBuilderInstantiation)!);
}
#endregion
if (!IsCreated())
throw new NotSupportedException(SR.NotSupported_TypeNotYetCreated);
- return CustomAttribute.GetCustomAttributes(m_bakedRuntimeType, (RuntimeType)typeof(object), inherit);
+ return CustomAttribute.GetCustomAttributes(m_bakedRuntimeType, (typeof(object) as RuntimeType)!, inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
public override object[] GetCustomAttributes(bool inherit)
{
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object));
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
#region ICustomAttributeProvider
public override object[] GetCustomAttributes(bool inherit)
{
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object));
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
bool wrapExceptions = (invokeAttr & BindingFlags.DoNotWrapExceptions) == 0;
if (actualCount > 0)
{
- object[] arguments = CheckArguments(parameters!, binder!, invokeAttr, culture, sig);
+ object[] arguments = CheckArguments(parameters!, binder, invokeAttr, culture, sig);
object retValue = RuntimeMethodHandle.InvokeMethod(null, arguments, sig, true, wrapExceptions);
// copy out. This should be made only if ByRef are present.
for (int index = 0; index < arguments.Length; index++)
private string? m_name;
private void* m_utf8name;
private RuntimeTypeCache m_reflectedTypeCache = null!;
- private RuntimeMethodInfo? m_addMethod = null;
+ private RuntimeMethodInfo? m_addMethod;
private RuntimeMethodInfo? m_removeMethod;
private RuntimeMethodInfo? m_raiseMethod;
private MethodInfo[]? m_otherMethod;
#region ICustomAttributeProvider
public override object[] GetCustomAttributes(bool inherit)
{
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object));
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
#region ICustomAttributeProvider
public override object[] GetCustomAttributes(bool inherit)
{
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object));
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
//
// first take care of all the NO_INVOKE cases.
if (ContainsGenericParameters ||
- IsDisallowedByRefType(ReturnType!) ||
+ IsDisallowedByRefType(ReturnType) ||
(declaringType != null && declaringType.ContainsGenericParameters) ||
((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs))
{
else
{
// Check for byref-like types
- if ((declaringType != null && declaringType.IsByRefLike) || ReturnType!.IsByRefLike)
+ if ((declaringType != null && declaringType.IsByRefLike) || ReturnType.IsByRefLike)
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS;
}
{
var sbName = new ValueStringBuilder(MethodNameBufferSize);
- sbName.Append(ReturnType!.FormatTypeName());
+ sbName.Append(ReturnType.FormatTypeName());
sbName.Append(' ');
sbName.Append(Name);
#region ICustomAttributeProvider
public override object[] GetCustomAttributes(bool inherit)
{
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object), inherit);
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!, inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
throw new MemberAccessException();
}
- else if (ReturnType!.IsByRef)
+ else if (ReturnType.IsByRef)
{
Type elementType = ReturnType.GetElementType()!;
if (elementType.IsByRefLike)
[Diagnostics.DebuggerHidden]
public override object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
{
- object[]? arguments = InvokeArgumentsCheck(obj, invokeAttr, binder!, parameters, culture);
+ object[]? arguments = InvokeArgumentsCheck(obj, invokeAttr, binder, parameters, culture);
bool wrapExceptions = (invokeAttr & BindingFlags.DoNotWrapExceptions) == 0;
if (arguments == null || arguments.Length == 0)
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
- private object[]? InvokeArgumentsCheck(object? obj, BindingFlags invokeAttr, Binder binder, object?[]? parameters, CultureInfo? culture)
+ private object[]? InvokeArgumentsCheck(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
{
Signature sig = Signature;
#endregion
#region MethodInfo Overrides
- public override Type? ReturnType
+
+#pragma warning disable CS8608 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
+ public override Type ReturnType
{
get { return Signature.ReturnType; }
}
- public override ICustomAttributeProvider? ReturnTypeCustomAttributes
+ public override ICustomAttributeProvider ReturnTypeCustomAttributes
{
get { return ReturnParameter; }
}
-#pragma warning disable CS8608 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
public override ParameterInfo ReturnParameter
{
get
#region ICustomAttributeProvider Members
public override object[] GetCustomAttributes(bool inherit)
{
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object));
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
CustomAttributeData.GetCustomAttributes(this), typeof(DateTimeConstantAttribute), 0);
if (value.ArgumentType != null)
- return new DateTime((long)value.Value!); // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
+ return new DateTime((long)value.Value!);
}
else
{
{
// This is not possible because Decimal cannot be represented directly in the metadata.
Debug.Fail("Decimal cannot be represented directly in the metadata.");
- return (decimal)namedArgument.TypedValue.Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
+ return (decimal)namedArgument.TypedValue.Value!;
}
}
if (parameters[2].ParameterType == typeof(uint))
{
// DecimalConstantAttribute(byte scale, byte sign, uint hi, uint mid, uint low)
- int low = (int)(uint)args[4].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- int mid = (int)(uint)args[3].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- int hi = (int)(uint)args[2].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- byte sign = (byte)args[1].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- byte scale = (byte)args[0].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
+ int low = (int)(uint)args[4].Value!;
+ int mid = (int)(uint)args[3].Value!;
+ int hi = (int)(uint)args[2].Value!;
+ byte sign = (byte)args[1].Value!;
+ byte scale = (byte)args[0].Value!;
return new System.Decimal(low, mid, hi, (sign != 0), scale);
}
else
{
// DecimalConstantAttribute(byte scale, byte sign, int hi, int mid, int low)
- int low = (int)args[4].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- int mid = (int)args[3].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- int hi = (int)args[2].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- byte sign = (byte)args[1].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
- byte scale = (byte)args[0].Value!; // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
+ int low = (int)args[4].Value!;
+ int mid = (int)args[3].Value!;
+ int hi = (int)args[2].Value!;
+ byte sign = (byte)args[1].Value!;
+ byte scale = (byte)args[0].Value!;
return new System.Decimal(low, mid, hi, (sign != 0), scale);
}
{
if (namedArgument.MemberInfo.Name.Equals("Value"))
{
- return new DateTime((long)namedArgument.TypedValue.Value!); // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
+ return new DateTime((long)namedArgument.TypedValue.Value!);
}
}
// Look at the ctor argument if the "Value" property was not explicitly defined.
- return new DateTime((long)attr.ConstructorArguments[0].Value!); // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34976
+ return new DateTime((long)attr.ConstructorArguments[0].Value!);
}
private static object? GetRawConstant(CustomAttributeData attr)
if (MdToken.IsNullToken(m_tkParamDef))
return Array.Empty<object>();
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object));
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
#region ICustomAttributeProvider
public override object[] GetCustomAttributes(bool inherit)
{
- return CustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object));
+ return CustomAttribute.GetCustomAttributes(this, (typeof(object) as RuntimeType)!);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
// Without this the reflectedType.Cache.GetMethod call below may return a MethodInfo
// object whose ReflectedType is string[] and DeclaringType is object[]. That would
// be (arguabally) incorrect because string[] is not a subclass of object[].
- MethodBase[] methodBases = (MethodBase[])reflectedType.GetMember(
+ MethodBase[] methodBases = (reflectedType.GetMember(
RuntimeMethodHandle.GetName(methodHandle), MemberTypes.Constructor | MemberTypes.Method,
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
+ BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) as MethodBase[])!;
bool loaderAssuredCompatible = false;
for (int i = 0; i < methodBases.Length; i++)
// ignoring instantiation is the ReflectedType a subtype of the DeclaringType
RuntimeType declaringDefinition = (RuntimeType)declaredType.GetGenericTypeDefinition();
- RuntimeType baseType = reflectedType;
+ RuntimeType? baseType = reflectedType;
while (baseType != null)
{
if (baseDefinition == declaringDefinition)
break;
- baseType = baseType.GetBaseType()!;
+ baseType = baseType.GetBaseType();
}
if (baseType == null)
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(ifaceType));
RuntimeTypeHandle ifaceRtTypeHandle = ifaceRtType.GetTypeHandleInternal();
- GetTypeHandleInternal().VerifyInterfaceIsImplemented(ifaceRtTypeHandle);
- Debug.Assert(ifaceType.IsInterface); // VerifyInterfaceIsImplemented enforces this invariant
- Debug.Assert(!IsInterface); // VerifyInterfaceIsImplemented enforces this invariant
+ GetTypeHandleInternal().VerifyInterfaceIsImplemented(ifaceRtTypeHandle);
+ Debug.Assert(ifaceType.IsInterface); // VerifyInterfaceIsImplemented enforces this invariant
+ Debug.Assert(!IsInterface); // VerifyInterfaceIsImplemented enforces this invariant
- // SZArrays implement the methods on IList`1, IEnumerable`1, and ICollection`1 with
- // SZArrayHelper and some runtime magic. We don't have accurate interface maps for them.
- if (IsSZArray && ifaceType.IsGenericType)
- throw new ArgumentException(SR.Argument_ArrayGetInterfaceMap);
+ // SZArrays implement the methods on IList`1, IEnumerable`1, and ICollection`1 with
+ // SZArrayHelper and some runtime magic. We don't have accurate interface maps for them.
+ if (IsSZArray && ifaceType.IsGenericType)
+ throw new ArgumentException(SR.Argument_ArrayGetInterfaceMap);
- int ifaceInstanceMethodCount = RuntimeTypeHandle.GetNumVirtuals(ifaceRtType);
+ int ifaceInstanceMethodCount = RuntimeTypeHandle.GetNumVirtuals(ifaceRtType);
- InterfaceMapping im;
- im.InterfaceType = ifaceType;
- im.TargetType = this;
- im.InterfaceMethods = new MethodInfo[ifaceInstanceMethodCount];
- im.TargetMethods = new MethodInfo[ifaceInstanceMethodCount];
+ InterfaceMapping im;
+ im.InterfaceType = ifaceType;
+ im.TargetType = this;
+ im.InterfaceMethods = new MethodInfo[ifaceInstanceMethodCount];
+ im.TargetMethods = new MethodInfo[ifaceInstanceMethodCount];
for (int i = 0; i < ifaceInstanceMethodCount; i++)
{
reflectedType = this;
// GetMethodBase will convert this to the instantiating/unboxing stub if necessary
- MethodBase rtTypeMethodBase = GetMethodBase(reflectedType, classRtMethodHandle)!;
+ MethodBase? rtTypeMethodBase = GetMethodBase(reflectedType, classRtMethodHandle);
// a class may not implement all the methods of an interface (abstract class) so null is a valid value
Debug.Assert(rtTypeMethodBase is null || rtTypeMethodBase is RuntimeMethodInfo);
im.TargetMethods[i] = (MethodInfo)rtTypeMethodBase!;
}
+
return im;
}
#endregion
{
if (type is null)
throw new ArgumentNullException(nameof(type));
-
RuntimeType? rtType = type as RuntimeType;
if (rtType == null)
return false;
if (argCnt != 1)
throw new ArgumentException(SR.Arg_FldSetArgErr, nameof(bindingFlags));
- selFld.SetValue(target!, providedArgs![0], bindingFlags, binder, culture);
+ selFld.SetValue(target, providedArgs![0], bindingFlags, binder, culture);
return null;
}
}
if ((bindingFlags & BindingFlags.InvokeMethod) != 0)
{
// Lookup Methods
- MethodInfo[] semiFinalists = (MethodInfo[])GetMember(name, MemberTypes.Method, bindingFlags);
+ MethodInfo[] semiFinalists = (GetMember(name, MemberTypes.Method, bindingFlags) as MethodInfo[])!;
List<MethodInfo>? results = null;
for (int i = 0; i < semiFinalists.Length; i++)
if (finalist == null && isGetProperty || isSetProperty)
{
// Lookup Property
- PropertyInfo[] semiFinalists = (PropertyInfo[])GetMember(name, MemberTypes.Property, bindingFlags);
+ PropertyInfo[] semiFinalists = (GetMember(name, MemberTypes.Property, bindingFlags) as PropertyInfo[])!;
List<MethodInfo>? results = null;
for (int i = 0; i < semiFinalists.Length; i++)
bool hasRelatedActivityID = RemoveFirstArgIfRelatedActivityId(ref args);
if (!(source != null && source.SelfDescribingEvents))
{
- Debug.Assert(eventData != null);
manifest.StartEvent(eventName, eventAttribute);
for (int fieldIdx = 0; fieldIdx < args.Length; fieldIdx++)
{
public override string ToString() => ScopeName;
- public static readonly TypeFilter FilterTypeName = (m, c) => FilterTypeNameImpl(m, c, StringComparison.Ordinal); // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/23268
+ public static readonly TypeFilter FilterTypeName = (m, c) => FilterTypeNameImpl(m, c, StringComparison.Ordinal);
public static readonly TypeFilter FilterTypeNameIgnoreCase = (m, c) => FilterTypeNameImpl(m, c, StringComparison.OrdinalIgnoreCase);
private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;