From c51ee93a85a8cd757df9eeb05f0d6b0ebd33027e Mon Sep 17 00:00:00 2001 From: apmoskevitz Date: Fri, 20 Sep 2024 14:21:48 -0400 Subject: [PATCH] focus on CS8769 --- .../CSharp/Resolver/CSharpResolver.cs | 6 +-- .../TypeSystem/CSharpTypeResolveContext.cs | 26 ++++----- .../IL/Transforms/TransformExpressionTrees.cs | 54 +++++++++---------- .../TypeSystem/GenericContext.cs | 6 +-- .../Implementation/DecoratedType.cs | 20 +++---- .../TypeSystem/Implementation/FakeMember.cs | 19 +++---- .../Implementation/MetadataEvent.cs | 4 +- .../Implementation/MetadataField.cs | 6 +-- .../Implementation/MetadataMethod.cs | 8 +-- .../Implementation/MetadataProperty.cs | 4 +- .../Implementation/MetadataTypeDefinition.cs | 4 +- .../Implementation/MinimalCorlib.cs | 44 +++++++-------- .../NullabilityAnnotatedType.cs | 2 +- .../Implementation/SyntheticRangeIndexer.cs | 4 +- ICSharpCode.Decompiler/Util/LazyInit.cs | 2 +- 15 files changed, 106 insertions(+), 103 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs index 239e3af97..bfe186000 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs @@ -154,7 +154,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver return WithContext(context.WithCurrentMember(member)); } - ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember member) + ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember? member) { return WithCurrentMember(member); } @@ -188,7 +188,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver /// /// Sets the current type definition. /// - public CSharpResolver WithCurrentTypeDefinition(ITypeDefinition typeDefinition) + public CSharpResolver WithCurrentTypeDefinition(ITypeDefinition? typeDefinition) { if (this.CurrentTypeDefinition == typeDefinition) return this; @@ -203,7 +203,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver checkForOverflow, isWithinLambdaExpression, newTypeDefinitionCache, localVariableStack, objectInitializerStack); } - ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition typeDefinition) + ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition? typeDefinition) { return WithCurrentTypeDefinition(typeDefinition); } diff --git a/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs b/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs index 9f8d94406..8a0374f2c 100644 --- a/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs +++ b/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Diagnostics.CodeAnalysis; using ICSharpCode.Decompiler.TypeSystem; @@ -25,10 +26,10 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem public sealed class CSharpTypeResolveContext : ITypeResolveContext { readonly IModule module; - readonly ResolvedUsingScope currentUsingScope; - readonly ITypeDefinition currentTypeDefinition; - readonly IMember currentMember; - readonly string[] methodTypeParameterNames; + readonly ResolvedUsingScope? currentUsingScope; + readonly ITypeDefinition? currentTypeDefinition; + readonly IMember? currentMember; + readonly string[]? methodTypeParameterNames; public CSharpTypeResolveContext(IModule module, ResolvedUsingScope? usingScope = null, ITypeDefinition? typeDefinition = null, IMember? member = null) { @@ -40,7 +41,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem this.currentMember = member; } - private CSharpTypeResolveContext(IModule module, ResolvedUsingScope usingScope, ITypeDefinition typeDefinition, IMember member, string[] methodTypeParameterNames) + private CSharpTypeResolveContext(IModule module, ResolvedUsingScope? usingScope, ITypeDefinition? typeDefinition, IMember? member, string[]? methodTypeParameterNames) { this.module = module; this.currentUsingScope = usingScope; @@ -49,7 +50,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem this.methodTypeParameterNames = methodTypeParameterNames; } - public ResolvedUsingScope CurrentUsingScope { + public ResolvedUsingScope? CurrentUsingScope { get { return currentUsingScope; } } @@ -61,30 +62,31 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem get { return module; } } - public ITypeDefinition CurrentTypeDefinition { + public ITypeDefinition? CurrentTypeDefinition { get { return currentTypeDefinition; } } - public IMember CurrentMember { + public IMember? CurrentMember { get { return currentMember; } } - public CSharpTypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition) + + public CSharpTypeResolveContext WithCurrentTypeDefinition(ITypeDefinition? typeDefinition) { return new CSharpTypeResolveContext(module, currentUsingScope, typeDefinition, currentMember, methodTypeParameterNames); } - ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition typeDefinition) + ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition? typeDefinition) { return WithCurrentTypeDefinition(typeDefinition); } - public CSharpTypeResolveContext WithCurrentMember(IMember member) + public CSharpTypeResolveContext WithCurrentMember(IMember? member) { return new CSharpTypeResolveContext(module, currentUsingScope, currentTypeDefinition, member, methodTypeParameterNames); } - ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember member) + ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember? member) { return WithCurrentMember(member); } diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs index fad963048..690a00150 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs @@ -153,7 +153,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// Converts a Expression.Lambda call into an ILFunction. /// If the conversion fails, null is returned. /// - (Func, IType) ConvertLambda(CallInstruction instruction) + (Func?, IType) ConvertLambda(CallInstruction instruction) { if (instruction.Method.Name != "Lambda" || instruction.Arguments.Count != 2 || instruction.Method.ReturnType.FullName != "System.Linq.Expressions.Expression" || instruction.Method.ReturnType.TypeArguments.Count != 1) return (null, SpecialType.UnknownType); @@ -198,7 +198,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - (Func, IType) ConvertQuote(CallInstruction invocation) + (Func?, IType) ConvertQuote(CallInstruction invocation) { if (invocation.Arguments.Count != 1) return (null, SpecialType.UnknownType); @@ -266,7 +266,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - (Func, IType) ConvertInstruction(ILInstruction instruction, IType? typeHint = null) + (Func?, IType) ConvertInstruction(ILInstruction instruction, IType? typeHint = null) { var (inst, type) = Convert(); @@ -289,7 +289,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } return (DoConvert, typeHint ?? type); - (Func, IType) Convert() + (Func?, IType) Convert() { switch (instruction) { @@ -446,7 +446,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return delegateType; } - (Func, IType) ConvertArrayIndex(CallInstruction invocation) + (Func?, IType) ConvertArrayIndex(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -473,7 +473,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (Convert, type.ElementType); } - (Func, IType) ConvertArrayLength(CallInstruction invocation) + (Func?, IType) ConvertArrayLength(CallInstruction invocation) { if (invocation.Arguments.Count != 1) return (null, SpecialType.UnknownType); @@ -483,7 +483,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (() => new LdLen(StackType.I4, converted()), context.TypeSystem.FindType(KnownTypeCode.Int32)); } - (Func, IType) ConvertBinaryNumericOperator(CallInstruction invocation, BinaryNumericOperator op, bool? isChecked = null) + (Func?, IType) ConvertBinaryNumericOperator(CallInstruction invocation, BinaryNumericOperator op, bool? isChecked = null) { if (invocation.Arguments.Count < 2) return (null, SpecialType.UnknownType); @@ -574,7 +574,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (null, SpecialType.UnknownType); } - (Func, IType) ConvertCall(CallInstruction invocation) + (Func?, IType) ConvertCall(CallInstruction invocation) { if (invocation.Arguments.Count < 2) return (null, SpecialType.UnknownType); @@ -697,7 +697,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return converted; } - (Func, IType) ConvertCast(CallInstruction invocation, bool isChecked) + (Func?, IType) ConvertCast(CallInstruction invocation, bool isChecked) { if (invocation.Arguments.Count < 2) return (null, SpecialType.UnknownType); @@ -711,7 +711,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (() => new ExpressionTreeCast(targetType, expr(), isChecked), targetType); } - (Func, IType) ConvertCoalesce(CallInstruction invocation) + (Func?, IType) ConvertCoalesce(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -742,7 +742,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms }, targetType); } - (Func, IType) ConvertComparison(CallInstruction invocation, ComparisonKind kind) + (Func?, IType) ConvertComparison(CallInstruction invocation, ComparisonKind kind) { if (invocation.Arguments.Count < 2) return (null, SpecialType.UnknownType); @@ -790,7 +790,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (() => new Comp(kind, lifting, utype.GetStackType(), utype.GetSign(), left(), right()), resultType); } - (Func, IType) ConvertCondition(CallInstruction invocation) + (Func?, IType) ConvertCondition(CallInstruction invocation) { if (invocation.Arguments.Count != 3) return (null, SpecialType.UnknownType); @@ -808,7 +808,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (() => new IfInstruction(condition(), trueInst(), falseInst()), trueInstType); } - (Func, IType) ConvertConstant(CallInstruction invocation) + (Func?, IType) ConvertConstant(CallInstruction invocation) { if (!MatchConstantCall(invocation, out var value, out var type)) return (null, SpecialType.UnknownType); @@ -821,7 +821,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (() => ConvertValue(value, invocation), type); } - (Func, IType) ConvertElementInit(CallInstruction invocation) + (Func?, IType) ConvertElementInit(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -849,7 +849,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (BuildCall, member.ReturnType); } - (Func, IType) ConvertField(CallInstruction invocation, IType typeHint) + (Func?, IType) ConvertField(CallInstruction invocation, IType typeHint) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -896,7 +896,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - (Func, IType) ConvertInvoke(CallInstruction invocation) + (Func?, IType) ConvertInvoke(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -922,7 +922,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (BuildCall, invokeMethod.ReturnType); } - (Func, IType) ConvertListInit(CallInstruction invocation) + (Func?, IType) ConvertListInit(CallInstruction invocation) { if (invocation.Arguments.Count < 2) return (null, SpecialType.UnknownType); @@ -978,7 +978,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (BuildBlock, ctor.DeclaringType); } - (Func, IType) ConvertLogicOperator(CallInstruction invocation, bool and) + (Func?, IType) ConvertLogicOperator(CallInstruction invocation, bool and) { if (invocation.Arguments.Count < 2) return (null, SpecialType.UnknownType); @@ -1016,7 +1016,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - (Func, IType) ConvertMemberInit(CallInstruction invocation) + (Func?, IType) ConvertMemberInit(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -1064,7 +1064,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (BuildBlock, ctor.DeclaringType); } - (Func, IType) ConvertNewArrayBounds(CallInstruction invocation) + (Func?, IType) ConvertNewArrayBounds(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -1085,7 +1085,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (() => new NewArr(type, indices.SelectArray(f => f())), new ArrayType(context.TypeSystem, type, arguments.Count)); } - (Func, IType) ConvertNewArrayInit(CallInstruction invocation) + (Func?, IType) ConvertNewArrayInit(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -1154,7 +1154,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - (Func, IType) ConvertNewObject(CallInstruction invocation) + (Func?, IType) ConvertNewObject(CallInstruction invocation) { switch (invocation.Arguments.Count) { @@ -1203,7 +1203,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (null, SpecialType.UnknownType); } - (Func, IType) ConvertNotOperator(CallInstruction invocation) + (Func?, IType) ConvertNotOperator(CallInstruction invocation) { if (invocation.Arguments.Count < 1) return (null, SpecialType.UnknownType); @@ -1229,7 +1229,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - (Func, IType) ConvertProperty(CallInstruction invocation) + (Func?, IType) ConvertProperty(CallInstruction invocation) { if (invocation.Arguments.Count < 2) return (null, SpecialType.UnknownType); @@ -1272,7 +1272,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (BuildProperty, member.ReturnType); } - (Func, IType) ConvertTypeAs(CallInstruction invocation) + (Func?, IType) ConvertTypeAs(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -1293,7 +1293,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (BuildTypeAs, type); } - (Func, IType) ConvertTypeIs(CallInstruction invocation) + (Func?, IType) ConvertTypeIs(CallInstruction invocation) { if (invocation.Arguments.Count != 2) return (null, SpecialType.UnknownType); @@ -1306,7 +1306,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return (null, SpecialType.UnknownType); } - (Func, IType) ConvertUnaryNumericOperator(CallInstruction invocation, BinaryNumericOperator op, bool? isChecked = null) + (Func?, IType) ConvertUnaryNumericOperator(CallInstruction invocation, BinaryNumericOperator op, bool? isChecked = null) { if (invocation.Arguments.Count < 1) return (null, SpecialType.UnknownType); diff --git a/ICSharpCode.Decompiler/TypeSystem/GenericContext.cs b/ICSharpCode.Decompiler/TypeSystem/GenericContext.cs index ddb41c94e..152175399 100644 --- a/ICSharpCode.Decompiler/TypeSystem/GenericContext.cs +++ b/ICSharpCode.Decompiler/TypeSystem/GenericContext.cs @@ -25,10 +25,10 @@ namespace ICSharpCode.Decompiler.TypeSystem { public readonly struct GenericContext { - public readonly IReadOnlyList ClassTypeParameters; - public readonly IReadOnlyList MethodTypeParameters; + public readonly IReadOnlyList? ClassTypeParameters; + public readonly IReadOnlyList? MethodTypeParameters; - public GenericContext(IReadOnlyList classTypeParameters) + public GenericContext(IReadOnlyList? classTypeParameters) { this.ClassTypeParameters = classTypeParameters; this.MethodTypeParameters = null; diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/DecoratedType.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/DecoratedType.cs index 5107044f2..5e9f1a587 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/DecoratedType.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/DecoratedType.cs @@ -44,12 +44,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public abstract bool Equals(IType other); - IEnumerable IType.GetAccessors(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetAccessors(Predicate? filter, GetMemberOptions options) { return baseType.GetAccessors(filter, options); } - IEnumerable IType.GetConstructors(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetConstructors(Predicate? filter, GetMemberOptions options) { return baseType.GetConstructors(filter, options); } @@ -64,42 +64,42 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return baseType.GetDefinitionOrUnknown(); } - IEnumerable IType.GetEvents(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetEvents(Predicate? filter, GetMemberOptions options) { return baseType.GetEvents(filter, options); } - IEnumerable IType.GetFields(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetFields(Predicate? filter, GetMemberOptions options) { return baseType.GetFields(filter, options); } - IEnumerable IType.GetMembers(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetMembers(Predicate? filter, GetMemberOptions options) { return baseType.GetMembers(filter, options); } - IEnumerable IType.GetMethods(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetMethods(Predicate? filter, GetMemberOptions options) { return baseType.GetMethods(filter, options); } - IEnumerable IType.GetMethods(IReadOnlyList typeArguments, Predicate filter, GetMemberOptions options) + IEnumerable IType.GetMethods(IReadOnlyList typeArguments, Predicate? filter, GetMemberOptions options) { return baseType.GetMethods(typeArguments, filter, options); } - IEnumerable IType.GetNestedTypes(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetNestedTypes(Predicate? filter, GetMemberOptions options) { return baseType.GetNestedTypes(filter, options); } - IEnumerable IType.GetNestedTypes(IReadOnlyList typeArguments, Predicate filter, GetMemberOptions options) + IEnumerable IType.GetNestedTypes(IReadOnlyList typeArguments, Predicate? filter, GetMemberOptions options) { return baseType.GetNestedTypes(typeArguments, filter, options); } - IEnumerable IType.GetProperties(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetProperties(Predicate? filter, GetMemberOptions options) { return baseType.GetProperties(filter, options); } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs index ca9b556d7..13426414a 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Reflection; using System.Reflection.Metadata; @@ -94,7 +95,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string INamedElement.Namespace => DeclaringType?.Namespace; - bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) + bool IMember.Equals(IMember? obj, TypeVisitor typeNormalization) { return Equals(obj); } @@ -152,10 +153,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation bool IMethod.HasBody => false; public bool IsAccessor => AccessorOwner is not null; - public IMember AccessorOwner { get; set; } + public IMember? AccessorOwner { get; set; } public MethodSemanticsAttributes AccessorKind { get; set; } - IMethod IMethod.ReducedFrom => null; + IMethod? IMethod.ReducedFrom => null; public IReadOnlyList Parameters { get; set; } = EmptyList.Instance; @@ -195,11 +196,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public bool CanGet => Getter is not null; public bool CanSet => Setter is not null; - public IMethod Getter { get; set; } - public IMethod Setter { get; set; } + public IMethod? Getter { get; set; } + public IMethod? Setter { get; set; } public bool IsIndexer { get; set; } public bool ReturnTypeIsRefReadOnly => false; - public IReadOnlyList Parameters { get; set; } + public IReadOnlyList Parameters { get; set; } = ImmutableArray.Empty; public override string ToString() => "FakeProperty " + ReturnType + " " + DeclaringType.Name + "." + Name + @@ -226,8 +227,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public bool CanAdd => AddAccessor is not null; public bool CanRemove => RemoveAccessor is not null; public bool CanInvoke => InvokeAccessor is not null; - public IMethod AddAccessor { get; set; } - public IMethod RemoveAccessor { get; set; } - public IMethod InvokeAccessor { get; set; } + public IMethod? AddAccessor { get; set; } + public IMethod? RemoveAccessor { get; set; } + public IMethod? InvokeAccessor { get; set; } } } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs index 023276071..d7f1be94b 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs @@ -164,7 +164,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}"; public string Namespace => DeclaringType?.Namespace ?? string.Empty; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is MetadataEvent ev) { @@ -178,7 +178,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return 0x7937039a ^ module.MetadataFile.GetHashCode() ^ handle.GetHashCode(); } - bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) + bool IMember.Equals(IMember? obj, TypeVisitor typeNormalization) { return Equals(obj); } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs index 4486c90f5..3970ea97c 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs @@ -258,7 +258,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } } - public object GetConstantValue(bool throwOnInvalidMetadata) + public object? GetConstantValue(bool throwOnInvalidMetadata) { object val = LazyInit.VolatileRead(ref this.constantValue); if (val != null) @@ -295,7 +295,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is MetadataField f) { @@ -309,7 +309,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return 0x11dda32b ^ module.MetadataFile.GetHashCode() ^ handle.GetHashCode(); } - bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) + bool IMember.Equals(IMember? obj, TypeVisitor typeNormalization) { return Equals(obj); } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs index a40902510..d81e86d3d 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs @@ -130,7 +130,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public bool HasBody => module.metadata.GetMethodDefinition(handle).HasBody(); - public IMember AccessorOwner { + public IMember? AccessorOwner { get { if (accessorOwner.IsNil) return null; @@ -294,7 +294,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } IMember IMember.MemberDefinition => this; - IMethod IMethod.ReducedFrom => null; + IMethod? IMethod.ReducedFrom => null; TypeParameterSubstitution IMember.Substitution => TypeParameterSubstitution.Identity; public ITypeDefinition DeclaringTypeDefinition { @@ -602,7 +602,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}"; public string Namespace => DeclaringType?.Namespace ?? string.Empty; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is MetadataMethod m) { @@ -616,7 +616,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return 0x5a00d671 ^ module.MetadataFile.GetHashCode() ^ handle.GetHashCode(); } - bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) + bool IMember.Equals(IMember? obj, TypeVisitor typeNormalization) { return Equals(obj); } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs index da2d8a4cf..70e24e735 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs @@ -298,7 +298,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}"; public string Namespace => DeclaringType?.Namespace ?? string.Empty; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is MetadataProperty p) { @@ -312,7 +312,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return 0x32b6a76c ^ module.MetadataFile.GetHashCode() ^ handle.GetHashCode(); } - bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) + bool IMember.Equals(IMember? obj, TypeVisitor typeNormalization) { return Equals(obj); } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs index 9d3b2fdc4..a020f991b 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs @@ -549,7 +549,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return this; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is MetadataTypeDefinition td) { @@ -563,7 +563,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return 0x2e0520f2 ^ module.MetadataFile.GetHashCode() ^ handle.GetHashCode(); } - bool IEquatable.Equals(IType other) + bool IEquatable.Equals(IType? other) { return Equals(other); } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs index 4f1b9cc8a..11740ab7d 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs @@ -62,13 +62,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string ISymbol.Name => "corlib"; SymbolKind ISymbol.SymbolKind => SymbolKind.Module; - Metadata.MetadataFile IModule.MetadataFile => null; + Metadata.MetadataFile? IModule.MetadataFile => null; INamespace IModule.RootNamespace => rootNamespace; public IEnumerable TopLevelTypeDefinitions => typeDefinitions.Where(td => td != null); public IEnumerable TypeDefinitions => TopLevelTypeDefinitions; - public ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName) + public ITypeDefinition? GetTypeDefinition(TopLevelTypeName topLevelTypeName) { foreach (var typeDef in typeDefinitions) { @@ -105,11 +105,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { readonly MinimalCorlib corlib; internal List childNamespaces = new List(); - public INamespace ParentNamespace { get; } + public INamespace? ParentNamespace { get; } public string FullName { get; } public string Name { get; } - public CorlibNamespace(MinimalCorlib corlib, INamespace parentNamespace, string fullName, string name) + public CorlibNamespace(MinimalCorlib corlib, INamespace? parentNamespace, string fullName, string name) { this.corlib = corlib; this.ParentNamespace = parentNamespace; @@ -127,7 +127,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation SymbolKind ISymbol.SymbolKind => SymbolKind.Namespace; ICompilation ICompilationProvider.Compilation => corlib.Compilation; - INamespace INamespace.GetChildNamespace(string name) + INamespace? INamespace.GetChildNamespace(string name) { return childNamespaces.FirstOrDefault(ns => ns.Name == name); } @@ -148,7 +148,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { this.corlib = corlib; this.typeCode = typeCode; - KnownTypeReference ktr = KnownTypeReference.Get(typeCode); + KnownTypeReference? ktr = KnownTypeReference.Get(typeCode); this.typeKind = ktr.typeKind; this.MetadataName = ktr.Name + (ktr.TypeParameterCount > 0 ? "`" + ktr.TypeParameterCount : ""); } @@ -168,10 +168,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public string MetadataName { get; } - ITypeDefinition IEntity.DeclaringTypeDefinition => null; - IType ITypeDefinition.DeclaringType => null; - IType IType.DeclaringType => null; - IType IEntity.DeclaringType => null; + ITypeDefinition? IEntity.DeclaringTypeDefinition => null; + IType? ITypeDefinition.DeclaringType => null; + IType? IType.DeclaringType => null; + IType? IEntity.DeclaringType => null; bool ITypeDefinition.HasExtensionMethods => false; bool ITypeDefinition.IsReadOnly => false; @@ -248,61 +248,61 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string INamedElement.Namespace => KnownTypeReference.Get(typeCode).Namespace; - bool IEquatable.Equals(IType other) + bool IEquatable.Equals(IType? other) { return this == other; } - IEnumerable IType.GetAccessors(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetAccessors(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } IEnumerable IEntity.GetAttributes() => EmptyList.Instance; bool IEntity.HasAttribute(KnownAttribute attribute) => false; - IAttribute IEntity.GetAttribute(KnownAttribute attribute) => null; + IAttribute? IEntity.GetAttribute(KnownAttribute attribute) => null; - IEnumerable IType.GetConstructors(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetConstructors(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetEvents(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetEvents(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetFields(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetFields(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetMembers(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetMembers(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetMethods(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetMethods(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetMethods(IReadOnlyList typeArguments, Predicate filter, GetMemberOptions options) + IEnumerable IType.GetMethods(IReadOnlyList typeArguments, Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetNestedTypes(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetNestedTypes(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetNestedTypes(IReadOnlyList typeArguments, Predicate filter, GetMemberOptions options) + IEnumerable IType.GetNestedTypes(IReadOnlyList typeArguments, Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } - IEnumerable IType.GetProperties(Predicate filter, GetMemberOptions options) + IEnumerable IType.GetProperties(Predicate? filter, GetMemberOptions options) { return EmptyList.Instance; } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs index abfd5b184..63b9d5085 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return visitor.VisitNullabilityAnnotatedType(this); } - public override bool Equals(IType other) + public override bool Equals(IType? other) { return other is NullabilityAnnotatedType nat && nat.nullability == nullability diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/SyntheticRangeIndexer.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/SyntheticRangeIndexer.cs index 2bc60031e..8c0072e2d 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/SyntheticRangeIndexer.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/SyntheticRangeIndexer.cs @@ -105,7 +105,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string INamedElement.ReflectionName => underlyingMethod.ReflectionName; string INamedElement.Namespace => underlyingMethod.Namespace; - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is SyntheticRangeIndexAccessor g && this.underlyingMethod.Equals(g.underlyingMethod) @@ -118,7 +118,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return underlyingMethod.GetHashCode() ^ indexOrRangeType.GetHashCode(); } - bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) + bool IMember.Equals(IMember? obj, TypeVisitor typeNormalization) { return obj is SyntheticRangeIndexAccessor g && this.underlyingMethod.Equals(g.underlyingMethod, typeNormalization) diff --git a/ICSharpCode.Decompiler/Util/LazyInit.cs b/ICSharpCode.Decompiler/Util/LazyInit.cs index d19344cd4..77589b46f 100644 --- a/ICSharpCode.Decompiler/Util/LazyInit.cs +++ b/ICSharpCode.Decompiler/Util/LazyInit.cs @@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.Util /// - If target is not null: returns target. /// [return: NotNullIfNotNull("newValue")] - public static T? GetOrSet(ref T? target, T? newValue) where T : class + public static T? GetOrSet([NotNullIfNotNull(nameof(newValue))] ref T? target, T? newValue) where T : class { T? oldValue = Interlocked.CompareExchange(ref target, newValue, null); return oldValue ?? newValue;